1.1.0 • Published 6 years ago

babel-plugin-reflective-import v1.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

Babel Plugin Relative Import

Import files for tests as easy if they are in the same folder as the tested. give your folder structure

src/
  component/
   fileTotest.js

__tests__/
  component/
    fileTotest.test.js

in your fileTotest.test.js

import componentTotest from '$/fileTotest.js';
// Gets compiled to:
import fooHelper from '../../src/fileTotest.js';
// No more unecessarie paths!

Quickstart

npm install babel-plugin-relative-import --save-dev

Add a .babelrc file and write:

{
  "plugins": [
    "babel-plugin-reflexive-import"
  ]
}

Options

You can use a custom root with the testPathFolder option. And you can set the off set between your source and test.

{
  "plugins": [
    ["babel-plugin-relative-import", {
      "testFolder": "__tests__",
      "srcFolder": "src"
    }]
  ]
}

Inspiration

Inspired by the babel-relative-import from Olivier Louvignes.