1 | # Babel Root Import
|
2 | Babel plugin to add the opportunity to use `import` with root based paths.<br>
|
3 |
|
4 | ## Example
|
5 | ```javascript
|
6 | // Usually
|
7 | import SomeExample from '../../../some/example.js';
|
8 |
|
9 | // With Babel-Root-Importer
|
10 | import SomeExample from '/some/example.js';
|
11 | ```
|
12 |
|
13 | ## Install
|
14 | ```
|
15 | npm install babel-root-slash-import --save-dev
|
16 | ```
|
17 |
|
18 | ## Use
|
19 | Add a `.babelrc` file and write:
|
20 | ```javascript
|
21 | {
|
22 | "plugins": [
|
23 | "babel-root-slash-import"
|
24 | ]
|
25 | }
|
26 | ```
|
27 | or pass the plugin with the plugins-flag on CLI
|
28 | ```
|
29 | babel-node myfile.js --plugins babel-root-slash-import
|
30 | ```
|
31 |
|
32 | ## Extras
|
33 | If you want a custom root because for example all your files are in the src/js folder you can define this in your `.babelrc` file
|
34 | ```javascript
|
35 | {
|
36 | "plugins": [
|
37 | ["babel-root-slash-import", {
|
38 | "rootPathSuffix": "src/js"
|
39 | }]
|
40 | ]
|
41 | }
|
42 | ```
|
43 |
|
44 | ## Motivate
|
45 | If you like this project just give it a star :) I like stars.
|