babel-plugin-import-export-rename

1.0.1 • Public • Published

babel-plugin-import-rename Build Status Dependency Status

Rename import sources with a RegExp like a boss.

Example

Maybe you want to remove .jsx extension from compiled files:

input.js

import Foo from './Foo.jsx'

.babelrc

{
  "presets": ["react", "es2015"],
  "plugins": [
    ["import-rename", {"^(.*)\\.jsx$": "$1"}]
  ]
}

output.js

'use strict';
var _Foo = require('./Foo');
var _Foo2 = _interopRequireDefault(_Foo);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

Usage

Specify sources and replacements as plugin options. Option keys are strings passed directly to the RegExp constructor for matching against import sources in your code. Option values are the replacements.

Via .babelrc (recommended)

{
  "plugins": [[
    "import-rename", {
      "regex1": "replacement1",
      "regex2": "replacement2"
    }
  ]]
}

Via Node API

require('babel-core').transform('code', {
  plugins: [[
    'import-rename', {
      'regex1': 'replacement1',
      'regex2': 'replacement2'
    }
  ]]
})

js-standard-style

Package Sidebar

Install

npm i babel-plugin-import-export-rename

Weekly Downloads

16,201

Version

1.0.1

License

ISC

Last publish

Collaborators

  • churpeau