Skip to content

Commit b016b6f

Browse files
author
Tommy Leunen
committed
docs: Add a note explaing how to update from module-alias to module-resolver
Fixes #76
1 parent a4cff68 commit b016b6f

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ _Note:_ It also works with `require()`, and you can alias a NPM module.
1818

1919
## Usage
2020

21+
If you're coming from babel-plugin-module-alias, please read this section: Updating from [babel-plugin-module-alias](#updating-from-babel-plugin-module-alias).
22+
2123
Install the plugin
2224

2325
```
@@ -41,6 +43,41 @@ Specify the plugin in your `.babelrc` with the custom root or alias. Here's an e
4143
```
4244
_Note:_ If you're using a custom extension (other than .js, .jsx, .es and .es6), you can add the `extensions` array in the config.
4345

46+
_Note 2:_ The "root" option also support a glob configuration, like `./src/**/components`.
47+
48+
49+
### Updating from babel-plugin-module-alias
50+
51+
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.
52+
53+
Updating is very easy, so for example if you had this configuration:
54+
```
55+
// This configuration is outdated, this is just an example
56+
{
57+
"plugins": [
58+
["module-alias", [
59+
{ "src": "./src/utils", "expose": "utils" },
60+
{ "src": "./src/components", "expose": "components" },
61+
{ "src": "./src/actions", "expose": "actions" },
62+
{ "src": "npm:lodash", "expose": "underscore" }
63+
]]
64+
]
65+
}
66+
```
67+
You ony have to update the plugin options to be like this:
68+
```json
69+
{
70+
"plugins": [
71+
["module-resolver", {
72+
"root": ["./src"],
73+
"alias": {
74+
"underscore": "lodash"
75+
}
76+
}]
77+
]
78+
}
79+
```
80+
4481
## ESLint plugin
4582

4683
If you're using ESLint, you should use the [eslint-plugin-import][eslint-plugin-import], and this [eslint-import-resolver-babel-module][eslint-import-resolver-babel-module] in order to remove falsy unresolved modules.

0 commit comments

Comments
 (0)