1.0.1 • Published 8 years ago

babel-plugin-import-export-rename v1.0.1

Weekly downloads
397
License
ISC
Repository
github
Last release
8 years ago

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