babel-plugin-import-export-rename

Rename import sources

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
babel-plugin-import-export-rename
421.0.16 years ago6 years agoMinified + gzip package size for babel-plugin-import-export-rename in KB

Readme

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