# babel-plugin-transform-rename-import

> Replace import sources

Latest version **2.3.0** (published 2018-07-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install babel-plugin-transform-rename-import
pnpm add babel-plugin-transform-rename-import
yarn add babel-plugin-transform-rename-import
bun add babel-plugin-transform-rename-import
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.3.0 |
| Published | 2018-07-01 |
| First published | 2016-01-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 44 |
| Author | Sigurd Fosseng |
| Maintainers | laat |

## Links

- npm: https://www.npmjs.com/package/babel-plugin-transform-rename-import
- Repository: https://github.com/laat/babel-plugin-transform-rename-import
- Homepage: https://github.com/laat/babel-plugin-transform-rename-import#readme
- Issues: https://github.com/laat/babel-plugin-transform-rename-import/issues
- npm.io page: https://npm.io/package/babel-plugin-transform-rename-import

## Recent versions

- 2.3.0 (latest) — 2018-07-01
- 2.2.0 — 2018-05-05
- 2.1.1 — 2017-09-07
- 2.1.0 — 2017-06-15
- 2.0.0 — 2016-09-09
- 1.1.5 — 2016-08-15
- 1.1.4 — 2016-07-21
- 1.1.3 — 2016-05-08
- 1.1.2 — 2016-04-30
- 1.1.1 — 2016-04-23
- 1.1.0 — 2016-04-22
- 1.0.5 — 2016-04-14
- 1.0.4 — 2016-04-12
- 1.0.3 — 2016-04-11
- 1.0.2 — 2016-03-14
- … 2 more at https://npm.io/package/babel-plugin-transform-rename-import/versions

## README

# babel-plugin-transform-rename-import [![Build Status][travis-image]][travis-url] [![npm][npm-image]][npm-url]
[npm-image]: https://img.shields.io/npm/v/babel-plugin-transform-rename-import.svg?style=flat
[npm-url]: https://npmjs.org/package/babel-plugin-transform-rename-import
[travis-image]: https://travis-ci.org/laat/babel-plugin-transform-rename-import.svg?branch=master
[travis-url]: https://travis-ci.org/laat/babel-plugin-transform-rename-import

> replace import sources

## Install

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

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

or multiple replacements:
```js
{
  "plugins": [
    ["transform-rename-import", {
      replacements: [
        { original: 'replace-me', replacement: 'replaced' },
        { original: 'replace-me2', replacement: 'replaced2' }
      ]
    }
  ]]
}
```

RegExp:
```js
{
  "plugins": [["transform-rename-import", { original: '^(.+?)\\.less$', replacement: '$1.css' }]]
}
```


## Programatic Usage

```javascript
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](https://github.com/laat)

---
_Source: https://npm.io/package/babel-plugin-transform-rename-import · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
