1.5.0 • Published 7 years ago
babel-plugin-module-require v1.5.0
babel-plugin-module-require
Transform module style requires to relative requires.
So instead of writing:
const TeamStore = require('../../../../stores/TeamStore');
you can just write:
const TeamStore = require('stores/TeamStore');
which will be transformed to the code above.
Installation
$ npm install --save babel-plugin-module-require
Usage
.babelrc, package.json or anywhere else where Babel works
{
"presets": ["es2015"],
"plugins": [
["module-require", {
"baseDir": "src",
"ignore": []
}]
]
}
Options
####baseDir:string (optional)
default: root directory where package.json
is located
The base directory relative to
package.json
where to resolve the modules
####ignore:array[string] (optional) default: []
Array of modules to ignore i.e. keep as it is.
Notes
- This plugin will transform only module style requires which don't seem to be installed npm packages. So it will ignore relative file paths and node packages (
../stores/TeamStore
andfs
both will stay untouched). - If node package is installed with the same name, that package will be prefered instead of the actual file you may refer. So be careful.
##Contributing
Issues and PRs are welcome.