babel-plugin-transform-rename-import
Replace import sources
Last updated a year ago by laat .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install babel-plugin-transform-rename-import 
SYNC missed versions from official npm registry.

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

Current Tags

  • 2.3.0                                ...           latest (a year ago)

17 Versions

  • 2.3.0                                ...           a year ago
  • 2.2.0                                ...           2 years ago
  • 2.1.1                                ...           2 years ago
  • 2.1.0                                ...           2 years ago
  • 2.0.0                                ...           3 years ago
  • 1.1.5                                ...           3 years ago
  • 1.1.4                                ...           3 years ago
  • 1.1.3                                ...           4 years ago
  • 1.1.2                                ...           4 years ago
  • 1.1.1                                ...           4 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.5                                ...           4 years ago
  • 1.0.4                                ...           4 years ago
  • 1.0.3                                ...           4 years ago
  • 1.0.2                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago

Copyright 2014 - 2017 © taobao.org |