babel-plugin-module-resolver
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
find-babel-config | 2.1.1 | 20.15 kB | MIT | prod | |
glob | 8.1.0 | 15.35 kB | ISC | prod | |
pkg-up | 3.1.0 | 1.97 kB | MIT | prod | |
reselect | 4.1.8 | 28.75 kB | MIT | prod | |
resolve | 1.22.8 | 26.69 kB | MIT | prod |
Babel-Plugin-Module-Resolver is a Babel plugin that allows you to add new "root" directories containing your modules and set up a custom alias for directories, specific files, or other npm modules. This function is particularly useful in simplifying the import/require paths in your code, letting you write utils/my-utils
instead of ../../../../utils/my-utils
, hence speeding up your workflows and eliminating the need to compute how many directory levels to traverse up before accessing a file.
Utilizing Babel-Plugin-Module-Resolver is straightforward. First, install the plugin by running npm install --save-dev babel-plugin-module-resolver
or yarn add --dev babel-plugin-module-resolver
. Subsequently, define the plugin in your .babelrc
with custom root or alias. Below is a usage example:
{
"plugins": [
["module-resolver", {
"root": ["./src"],
"alias": {
"test": "./test",
"underscore": "lodash"
}
}]
]
}
In case you're using a .babelrc.js
, specify the plugin like this:
const plugins = [
[
require.resolve('babel-plugin-module-resolver'),
{
root: ["./src/"],
alias: {
"test": "./test"
}
}
]
];
You can find the detailed documentation for Babel-Plugin-Module-Resolver at DOCS.md. Here, you'll find comprehensive information about the plugin, including how to configure and control it. In addition, if you're a plugin author, you'll find the documented exposed functions quite useful. This ensures you've got all the information necessary to get the most out of Babel-Plugin-Module-Resolver.