babel-plugin-transform-rename-import
replace import sources
Install
$ npm install --save babel-plugin-transform-rename-import
babelrc
{
"plugins": [["transform-rename-import", { original: 'assert', replacement: 'power-assert' }]]
}
or multiple replacements:
{
"plugins": [
["transform-rename-import", [
{ original: 'replace-me', replacement: 'replaced' },
{ original: 'replace-me2', replacement: 'replaced2' }
]
]]
}
RegExp:
{
"plugins": [["transform-rename-import", { original: '^(.+?)\\.less$', replacement: '$1.css' }]]
}
Programatic Usage
import plugin from 'babel-plugin-transform-rename-import'
import { transform } from 'babel-core'
function replace (code, original, replacement) {
return transform(code, {
babelrc: false,
plugins: [
[plugin, { original, replacement} ],
],
}).code;
}
replace("require('foo')", 'foo', 'bar')
replace("import foo from 'foo'", 'foo', 'bar')
replace("require('foo/thingy')", 'foo', 'bar')
replace("require('foo/thingy.less')", '^(.+?)\\.less$', '$1.css')
License
MIT © Sigurd Fosseng