babel-root-import-fragment

3.2.7 • Public • Published

Babel Root Import Fragment

Babel plugin to add the opportunity to use import with root based paths.

Example

// Usually
import SomeExample from '../../../app/some/example.js';

// With Babel-Root-Importer
import SomeExample from 'app/some/example.js';

Install

npm install babel-root-import-fragment --save-dev

Use

Add a .babelrc file and write:

{
  "plugins": [
    ["babel-root-import-fragment", {
      "rootPathPrefix": "app"
    }]
  ]
}

// Now you can use the plugin like:
import foo from 'app/my-file';

Extras

Custom root-path-suffix

Do you have a build folder? Add this in your .babelrc file

{
  "plugins": [
    ["babel-root-import-fragment", {
      "rootPathPrefix": "app"
      "rootPathSuffix": "build"
    }]
  ]
}

This will redirect the compiled files to the correct folder

Motivate

If you like this project just give it a star :) I like stars.

Readme

Keywords

none

Package Sidebar

Install

npm i babel-root-import-fragment

Weekly Downloads

2

Version

3.2.7

License

MIT

Last publish

Collaborators

  • pietrovismara