node package manager

babel-plugin-transform-rename-import

babel-plugin-transform-rename-import Build Status npm

replace import sources

Install

$ npm install --save babel-plugin-transform-rename-import

babelrc

{
  "plugins": [["transform-rename-import", { original: 'assert', replacement: 'power-assert' }]]
}

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')
//=> "require('bar');" 
 
replace("import foo from 'foo'", 'foo', 'bar')
//=> "import foo from 'bar';" 
 
replace("require('foo/thingy')", 'foo', 'bar')
//=> "require('bar/thingy');" 

License

MIT © Sigurd Fosseng