babel-plugin-require-root-rewrite
v1.0.2
Published
A Babel plugin for requiring files relative to the project root.
Downloads
1,942
Readme
babel-plugin-require-root-rewrite
A Babel plugin for requiring files relative to the project root.
Example
In: /path/to/project/containers/Register/Register.js
const BaseAuthForm = require('~/components/BaseAuthForm');
or
import BaseAuthForm from '~/components/BaseAuthForm';
Out
var BaseAuthForm = require('../../components/BaseAuthForm');
Installation
$ npm install babel-plugin-require-root-rewrite
Usage
Via .babelrc
(Recommended)
.babelrc
{
"plugins": [
["babel-plugin-require-root-rewrite", {
"pattern": "^~/",
"basePath": "lib",
"overrides": [
"api",
"server"
]
}]
]
}
Via CLI
$ babel --plugins babel-plugin-require-root-rewrite script.js
Via Node API
require('babel-core').transform('code', {
plugins: ['babel-plugin-require-root-rewrite']
});