babel-plugin-import-rename
v1.0.1
Published
Rename import sources
Downloads
7,877
Maintainers
Readme
babel-plugin-import-rename
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'
}
]]
})