Naturally Pacifist Marsupials
    Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    babel-plugin-transform-rename-importpublic

    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", [
          { 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

    404

    version

    2.1.1

    license

    MIT

    repository

    github.com

    last publish

    collaborators

    • avatar