Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
babel-plugin-module-resolver
Advanced tools
The babel-plugin-module-resolver npm package allows you to customize the resolution of modules in your Babel projects. It can be used to alias paths, so you don't have to deal with relative paths, and it can also help in organizing the project's structure more logically from a developer's perspective.
Custom Aliases
This feature allows you to define custom aliases for directories within your project. Instead of using relative paths, you can use the aliases to require modules, making the code cleaner and easier to maintain.
{
"plugins": [
["module-resolver", {
"alias": {
"@app": "./src/app",
"@models": "./src/models"
}
}]
]
}
Extension Resolution
This feature enables you to specify which file extensions should be resolved by the plugin. This can be useful when you are working with different types of JavaScript files and want to import them without specifying the extension.
{
"plugins": [
["module-resolver", {
"extensions": [
".js",
".jsx"
]
}]
]
}
Root Directory Configuration
By setting a root directory, you can simplify the import statements in your project. This feature allows you to set a base directory from which all the modules will be resolved.
{
"plugins": [
["module-resolver", {
"root": ["./src"]
}]
]
}
This package is used with webpack to automatically resolve modules based on the paths defined in tsconfig.json. It is similar to babel-plugin-module-resolver but is specifically tailored for TypeScript projects using webpack.
This package is an ESLint resolver that allows you to configure aliases for module paths, similar to babel-plugin-module-resolver. It is used to help ESLint understand the custom path aliases defined in your project.
Aliasify is a Browserify transform that provides similar aliasing functionality to babel-plugin-module-resolver. It allows you to rewrite module calls in your Browserify bundles, but it is specific to the Browserify ecosystem.
A babel plugin to add a new resolver for your modules when compiling your code using Babel. The plugin allows you to add new "root" directories that contains your modules. It also allows you to setup custom alias which can also be directories or specific files, or even other npm modules.
The reason of this plugin is to simplify the require/import paths in your project. Therefore, instead of using complex relative paths like ../../../../utils/my-utils
, you would be able to write 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.
// 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');
If you're coming from babel-plugin-module-alias, please read this section: Updating from babel-plugin-module-alias.
Install the plugin
$ npm install --save-dev babel-plugin-module-resolver
Specify the plugin in your .babelrc
with the custom root or alias. Here's an example:
{
"plugins": [
["module-resolver", {
"root": ["./src"],
"alias": {
"test": "./test",
"underscore": "lodash"
}
}]
]
}
root
: Array of root directories. Specify the paths or a glob path (eg. ./src/**/components
)alias
: Map of alias. You can also alias node_modules dependencies, not just local files.extensions
: Array of extensions used in the resolver. Override the default extensions (['.js', '.jsx', '.es', '.es6']
).cwd
: By default, the working directory is the one used for the resolver, but you can override it for your project.
babelrc
will make the plugin look for the closest babelrc configuration based on the file to parse.babel-plugin-module-resolver is a new version of the old babel-plugin-module-alias. Therefore, you also need to make a few modifications to your plugin configuration to make it work with this new plugin.
Updating is very easy, so for example if you had this configuration:
// This configuration is outdated, this is just an example
{
"plugins": [
["module-alias", [
{ "src": "./src/utils", "expose": "utils" },
{ "src": "./src/components", "expose": "components" },
{ "src": "./src/actions", "expose": "actions" },
{ "src": "npm:lodash", "expose": "underscore" }
]]
]
}
You ony have to update the plugin options to be like this:
{
"plugins": [
["module-resolver", {
"root": ["./src"],
"alias": {
"underscore": "lodash"
}
}]
]
}
If you're using ESLint, you should use the eslint-plugin-import, and this eslint-import-resolver-babel-module in order to remove falsy unresolved modules.
babel-plugin-module-resolver
option.MIT, see LICENSE.md for details.
2.5.0 (2017-02-05)
<a name="2.4.0"></a>
FAQs
Module resolver plugin for Babel
The npm package babel-plugin-module-resolver receives a total of 1,521,656 weekly downloads. As such, babel-plugin-module-resolver popularity was classified as popular.
We found that babel-plugin-module-resolver demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.