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
+22Lines changed: 22 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,6 +53,28 @@ Specify the plugin in your `.babelrc` with the custom root or alias. Here's an e
53
53
-`cwd`: By default, the working directory is the one used for the resolver, but you can override it for your project.
54
54
- The custom value `babelrc` will make the plugin look for the closest babelrc configuration based on the file to parse.
55
55
56
+
### Regular expression alias
57
+
58
+
It is possible to specify an alias using a regular expression. To do that, either start an alias with `'^'` or end it with `'$'`:
59
+
60
+
```json
61
+
{
62
+
"plugins": [
63
+
["module-resolver", {
64
+
"alias": {
65
+
"^@namespace/foo-(.+)": "packages/\\1"
66
+
}
67
+
}]
68
+
]
69
+
}
70
+
```
71
+
72
+
Using the config from this example `'@namespace/foo-bar'` will become `'packages/bar'`.
73
+
74
+
You can reference the n-th matched group with `'\\n'` (`'\\0'` refers to the whole matched path).
75
+
76
+
To use the backslash character (`\`) just escape it like so: `'\\\\'` (double escape is needed because of JSON already using `\` for escaping).
77
+
56
78
### Updating from babel-plugin-module-alias
57
79
58
80
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.
0 commit comments