You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+16-11Lines changed: 16 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,14 +7,18 @@ A [babel](http://babeljs.io) plugin to add a new resolver for your modules when
7
7
8
8
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.
_Note:_ It also works with `require()`, and you can alias a NPM module.
18
22
19
23
## Usage
20
24
@@ -30,7 +34,6 @@ Specify the plugin in your `.babelrc` with the custom root or alias. Here's an e
30
34
```json
31
35
{
32
36
"plugins": [
33
-
"transform-object-rest-spread",
34
37
["module-resolver", {
35
38
"root": ["./src"],
36
39
"alias": {
@@ -41,19 +44,21 @@ Specify the plugin in your `.babelrc` with the custom root or alias. Here's an e
41
44
]
42
45
}
43
46
```
44
-
_Note:_ All paths must be relative to the `.babelrc` files.
45
47
46
-
_Note 2:_ If you're using a custom extension (other than .js, .jsx, .es and .es6), you can add the `extensions` array in the config.
47
-
48
-
_Note 3:_ The "root" option also support a glob configuration, like `./src/**/components`.
48
+
### Options
49
49
50
+
-`root`: Array of root directories. Specify the paths or a glob path (eg. `./src/**/components`)
51
+
-`alias`: Map of alias. You can also alias node_modules dependencies, not just local files.
52
+
-`extensions`: Array of extensions used in the resolver. Override the default extensions (`['.js', '.jsx', '.es', '.es6']`).
53
+
-`cwd`: By default, the working directory is the one used for the resolver, but you can override it for your project.
54
+
- The custom value `babelrc` will make the plugin look for the closest babelrc configuration based on the file to parse.
50
55
51
56
### Updating from babel-plugin-module-alias
52
57
53
58
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.
54
59
55
60
Updating is very easy, so for example if you had this configuration:
56
-
```
61
+
```json
57
62
// This configuration is outdated, this is just an example
0 commit comments