# babel-plugin-transform-import-paths

> Babel plugin to transform import paths

Latest version **1.0.3** (published 2020-05-15) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2020-05-15 |
| First published | 2018-06-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Anthony Nichols |
| Maintainers | anichols |
| Keywords | babel, plugin, transform, import, paths |

## Links

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

## Dependencies (1)

- [slash](https://npm.io/package/slash.md) ^3.0.0

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 1.0.3 (latest) — 2020-05-15
- 1.0.2 — 2019-07-15
- 1.0.1 — 2019-03-25
- 1.0.0 — 2018-06-04

## README

# Babel Plugin Transform Import Paths
Similar to Webpack's [`resolve.alias`](https://webpack.js.org/configuration/resolve/#resolve-alias), this plugin transforms `import`, `export`, and `require` paths.

>This plugin is inspired by [`babel-plugin-root-imports`](https://github.com/entwicklerstube/babel-plugin-root-import)

- Babel v7 has changed their plugin options API, which broke configuring multiple path in `babel-plugin-root-imports`.
- I wanted a succinct syntax similar to Webpack's `resolve.alias` configuration.
- Typescript doesn't support transforming paths during compile (despite supporting the `baseUrl` and `paths` configuration options for resolving modules). This will allow using Babel v7 to transpile Typescript and transforming paths. Or, you can transpile using Typescript and then run Babel on the Typescript-transpiled code just to transform the paths.

## Install
**npm**
```
npm install --save-dev babel-plugin-transform-import-paths
```
**yarn**
```
yarn add --dev babel-plugin-transform-import-paths
```

## Usage
In your `.baberc` or `.babelrc.js` file:
```javascript
{
  "plugins": [
    ["babel-plugin-transform-import-paths", {
      "~": "src",
    }]
  ]
}
```

## Example

```javascript
// Before
import { Menu } from "~/components";
// After
import { Menu } from "../../../components";
```

Pass multiple paths
```javascript
// .babelrc or .babelrc.js
{
  "plugins": [
    ["babel-plugin-transform-import-paths", {
      "~": "src",
      "_": "src/something/nested",
      "MyFiles": "src/my-files"
    }]
  ]
}

// src/some/nested/file/index.js
import Foo from "~/location-of-foo";
import Bar from "_/location-of-bar";
import Baz from "MyFiles";

// After
import Foo from "../../location-of-foo";
import Bar from "../../something/nested/location-of-bar";
import Baz from "../../my-files";
```

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