global-modulize
Version:
Make it easy to import any file by using config file.
43 lines (31 loc) • 911 B
Markdown
[](https://travis-ci.org/dinfer/global-modulize)
Import a file by path is painful.
Change the structure of folder likes a tragedy.
So make it accessible globally.
```js
// before
const lib = require('../../../folder/file');
// after
const gm = require('gm');
const lib = gm('lib-name');
```
When you move the file to another place, what you need is set the config file. Not all the files import the file.
Create a config file named `.gm.js` to config name and which file the name is pointing.
```js
export default {
root: '/',
entries: {
name1: './path/to/the/file1',
name2: './path/to/the/file2',
},
};
```
Then, when you want to import a file, use it like this:
```js
const gm = require('global-modulize');
const lib1 = gm('name1');
const lib2 = gm('name2');
```