JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 57
  • Score
    100M100P100Q78955F
  • License MIT

Transform module style requires to relative requires

Package Exports

  • babel-plugin-module-require

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (babel-plugin-module-require) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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.