@share911/babel-root-slash-import

Babel Plugin to enable relative root-import

Usage no npm install needed!

<script type="module">
  import share911BabelRootSlashImport from 'https://cdn.skypack.dev/@share911/babel-root-slash-import';
</script>

README

Babel Root Import

Babel plugin to change the behaviour of import to root based paths.

Example

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

// With babel-root-slash-import
import SomeExample from '/some/example.js'

Install

npm install --save-dev babel-root-slash-import
yarn add --dev babel-root-slash-import

Use

Add a .babelrc file and write:

{
  "plugins": [
    "babel-root-slash-import"
  ]
}

or pass the plugin with the plugins-flag on CLI

npx babel-node myfile.js --plugins babel-root-slash-import

Extras

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

{
  "plugins": [
    ["babel-root-slash-import", {
      "rootPathSuffix": "src/js"
    }]
  ]
}

Motivate

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