Babel plugin to add the opportunity to use import with root based paths.
// Usually
import SomeExample from '../../../some/example.js';
// With Babel-Root-Importer
import SomeExample from '~/some/example.js';npm install babel-root-import --save-dev
Add a .babelrc file and write:
{
"plugins": [
"babel-root-import"
]
}or pass the plugin with the plugins-flag on CLI
babel-node myfile.js --plugins babel-root-import
If you want a custom root because for example all your files are in the src/js folder you can define this in your .babelrc file
{
"plugins": [
["babel-root-import", {
"rootPathSuffix": "src/js"
}]
]
}If you don't like the ~ syntax you can just use your own symbole (for example a @ symbole or \)
{
"plugins": [
["babel-root-import", {
"rootPathPrefix": "@"
}]
]
}
// Now you can use the plugin like:
import foo from '@/my-file';If you like this project just give it a star :) I like stars.
- Fix custom suffix in path, missing
/in generated paths
- Support Windows-Filesystem
- Add possibility to configure a custom rootPath-Symbole (instead of
~you can use whatever you like)
- Add possibility config the custom root path
- Updated plugin to new babel6 API
- Splitted tests and functions into two scopes with single tests
- Removed the "extra-root" param for the .babelrc since this is no yet supported in babel6
Breaking Change to Babel 5
- Updated to Babel 6
- Added integration tests
- Added / updated tests
- Implemented ESlint