Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-transform-rename-import

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-rename-import

Replace import sources

  • 2.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
97K
increased by38.83%
Maintainers
1
Weekly downloads
 
Created
Source

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

FAQs

Package last updated on 07 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc