babel-plugin-transform-rename-import
replace import sources
Install
$ npm install --save babel-plugin-transform-rename-import
Usage
import visitor from 'babel-plugin-transform-rename-import'
import traverse from 'babel-traverse'
import generate from 'babel-generator'
import { transform } from 'babel-core'
function replace (code, original, replacement) {
const { ast } = transform(code)
traverse(ast, visitor({ replacement, original }).visitor)
return generate(ast, {}, code).code.trim()
}
replace("require('foo')", 'foo', 'bar')
replace("import foo from 'foo'", 'foo', 'bar')
License
MIT © Sigurd Fosseng