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
feat: Add support for custom root directories (#69)
* feat: Add support for custom root directories
Fixes#46
BREAKING CHANGE: There's a new way to specify alias in the plugin options. See README for more info
A [babel](http://babeljs.io) plugin to rewrite (map, alias, resolve) directories as different directories during the Babel process. It's particularly useful when you have files you don't want to use with relative paths (especially in big projects).
4
+
A [babel](http://babeljs.io) 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 your to setup custom alias which can also be directories or specific files, or even other npm modules.
5
5
6
6
## Description
7
7
8
-
Instead of using relative paths in your project, you'll be able to use an alias. Here an simple example:
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.
9
+
10
+
Here's a full example:
9
11
```js
10
12
// Instead of using this;
11
13
importMyUtilFnfrom'../../../../utils/MyUtilFn';
12
14
// Use that:
13
15
importMyUtilFnfrom'utils/MyUtilFn';
14
16
```
15
-
With this plugin, you'll be able to map files or directories to the path you want.
16
17
17
18
_Note:_ It also work for `require()`.
18
19
@@ -24,34 +25,45 @@ _Note 2:_ You can use the `npm:` prefix in your plugin configuration to map a no
If you're using [eslint-plugin-import][eslint-plugin-import], you should use [eslint-import-resolver-babel-module-alias][resolver-module-alias] to avoid having false errors.
47
+
## ESLint plugin
48
+
49
+
If you're using ESLint, you should use the [eslint-plugin-import][eslint-plugin-import], and this [eslint-import-resolver-babel-module-resolver][eslint-import-resolver-babel-module-resolver] in order to remove falsy unresolved modules.
50
+
51
+
## Editors autocompletion
52
+
53
+
- Atom: Uses [atom-autocomplete-modules][atom-autocomplete-modules] and enable the `babel-plugin-module-resolver` option.
54
+
- IntelliJ/WebStorm: You can add custom resources root directories, make sure it matches what you have in this plugin.
0 commit comments