Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

babel-plugin-transform-rename-import

2.3.0 • Public • Published

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' }]]
}

or multiple replacements:

{
  "plugins": [
    ["transform-rename-import", {
      replacements: [
        { 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')
//=> "require('bar');"
 
replace("import foo from 'foo'", 'foo', 'bar')
//=> "import foo from 'bar';"
 
replace("require('foo/thingy')", 'foo', 'bar')
//=> "require('bar/thingy');"
 
replace("require('foo/thingy.less')", '^(.+?)\\.less$', '$1.css')
//=> "require('foo/thingy.css');"

License

MIT © Sigurd Fosseng

Keywords

none

Install

npm i babel-plugin-transform-rename-import

DownloadsWeekly Downloads

36,279

Version

2.3.0

License

MIT

Unpacked Size

6.55 kB

Total Files

4

Last publish

Collaborators

  • avatar