摆脱 dot hell 最简单的方式

1,016 阅读1分钟

Node Root helps you get away from dot hell like require('../../../lib/')

Usage

Simply install via npm install node-root -S

If you have a project tree like this:

/your/project/home
├─library
│   └─components
│       └─header.jsx
└─node_modules
    └─node-root

you can easily locate that header.jsx

import root from 'node-root'

import header from root('library/components/header.jsx')

The directory where you install node-root will be recognized as project's root, eg: node_modules/other is the root for node_modules/other/node_modules/node-root.

MIT.