0.0.2 • Published 6 years ago
@mrjs/babel-plugin-sresolver v0.0.2
babel-plugin-sresolver
A Babel plugin to add a new resolver for your modules when compiling your code using Babel.
Description
Default Node only load modules from node_modules
folder.
This plugin can autoload all package.json
files recursively, so you can named your library to require/import every where from your workspace.
For example, instead of using complex relative paths like ../../../../utils/my-utils
you can place use @utils/my-utils
.
It will allow you to work faster since you won't need to calculate how many levels of directory you have to go up before accessing the file.
{
"name": "@utils",
"main": "./"
}
// Use this:
import MyUtilFn from '@utils/MyUtilFn';
// Instead of that:
import MyUtilFn from '../../../../utils/MyUtilFn';
// And it also work with require calls
// Use this:
const MyUtilFn = require('@utils/MyUtilFn');
// Instead of that:
const MyUtilFn = require('../../../../utils/MyUtilFn');
Getting started
Install the plugin
$ npm install --save-dev @mrjs/babel-plugin-sresolver
Specify the plugin in your .babelrc
.Here's an example:
{
"plugins": [
["@mrjs/babel-plugin-sresolver"]
]
}
or custom root folder for scan package.json
{
"plugins": [
["@mrjs/babel-plugin-sresolver", {
"root": ["./src"],
}]
]
}
License
MIT, see LICENSE.md for details.
Are you also using it? Send a PR!