babel-plugin-module-require

1.5.0 • Public • Published

babel-plugin-module-require

Transform module style requires to relative requires.

So instead of writing:

const TeamStore = require('../../../../stores/TeamStore');

you can just write:

const TeamStore = require('stores/TeamStore');

which will be transformed to the code above.

Installation

$ npm install --save babel-plugin-module-require

Usage

.babelrc, package.json or anywhere else where Babel works

{
  "presets": ["es2015"],
  "plugins": [
    ["module-require", {
      "baseDir": "src",
      "ignore": []
    }]
  ]
}

Options

baseDir:string (optional)

default: root directory where package.json is located

The base directory relative to package.json where to resolve the modules

ignore:array[string] (optional)

default: []

Array of modules to ignore i.e. keep as it is.

Notes

  • This plugin will transform only module style requires which don't seem to be installed npm packages. So it will ignore relative file paths and node packages (../stores/TeamStore and fs both will stay untouched).
  • If node package is installed with the same name, that package will be prefered instead of the actual file you may refer. So be careful.

Contributing

Issues and PRs are welcome.

/babel-plugin-module-require/

    Package Sidebar

    Install

    npm i babel-plugin-module-require

    Weekly Downloads

    62

    Version

    1.5.0

    License

    MIT

    Last publish

    Collaborators

    • vahagnaharonian