# rollup-plugin-alias

> Resolves aliases with Rollup

Latest version **2.2.0** (published 2019-10-21) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install rollup-plugin-alias
pnpm add rollup-plugin-alias
yarn add rollup-plugin-alias
bun add rollup-plugin-alias
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.2.0 |
| Published | 2019-10-21 |
| First published | 2016-02-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 16.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 171 |
| Author | Johannes Stein |
| Maintainers | lukastaegert, rich_harris, stoney |
| Keywords | rollup, rollup-plugin, resolve, alias |

## Links

- npm: https://www.npmjs.com/package/rollup-plugin-alias
- Repository: https://github.com/frostney/rollup-plugin-alias
- Homepage: https://github.com/frostney/rollup-plugin-alias#readme
- Issues: https://github.com/frostney/rollup-plugin-alias/issues
- npm.io page: https://npm.io/package/rollup-plugin-alias

## 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

- 2.2.0 (latest) — 2019-10-21
- 2.1.0 — 2019-10-18
- 2.0.1 — 2019-09-27
- 2.0.0 — 2019-08-22
- 1.5.2 — 2019-06-01
- 1.5.1 — 2018-12-11
- 1.5.0 — 2018-12-11
- 1.4.0 — 2017-10-19
- 1.3.1 — 2017-04-17
- 1.3.0 — 2017-04-10
- 1.2.1 — 2017-03-07
- 1.2.0 — 2016-04-23
- 1.1.0 — 2016-04-19
- 1.0.2 — 2016-02-29
- 1.0.1 — 2016-02-29
- … 1 more at https://npm.io/package/rollup-plugin-alias/versions

## README

# rollup-plugin-alias
Define aliases when bundling packages with Rollup.

[![Build Status](https://travis-ci.org/rollup/rollup-plugin-alias.svg?branch=master)](https://travis-ci.org/rollup/rollup-plugin-alias) [![Dependency Status](https://david-dm.org/frostney/rollup-plugin-alias.svg)](https://david-dm.org/frostney/rollup-plugin-alias) [![devDependency Status](https://david-dm.org/frostney/rollup-plugin-alias/dev-status.svg)](https://david-dm.org/frostney/rollup-plugin-alias#info=devDependencies) [![Coverage Status](https://coveralls.io/repos/github/frostney/rollup-plugin-alias/badge.svg?branch=master)](https://coveralls.io/github/frostney/rollup-plugin-alias?branch=master)

Let's take a simple import as an example:

```javascript
import something from '../../../something';

something();
```

This probably doesn't look too bad on its own. But imagine this is not the only instance in your code base and after a refactor/restructuring this might fall over. With this plugin in place, you can alias `../../../something` with `something` for readability. In case of a refactor only the alias would need to be changed instead of navigating through the code base and changing all imports.

```javascript
import something from 'something';

something();
```

When we write tests, we may want an easier way to access the local library we are testing or mocking libraries. We may also define aliases to counteract "require hell" and get rid of all those `../../../` imports we may have in the process.

For Webpack users: This is a plugin to mimic the `resolve.alias` functionality in Rollup.

## Installation
```
$ npm install rollup-plugin-alias
```
#
## Usage
```javascript
// rollup.config.js
import alias from 'rollup-plugin-alias';

export default {
  input: './src/index.js',
  plugins: [
    alias({
      resolve: ['.jsx', '.js'], //optional, by default this will just look for .js files or folders
      entries:[
        {find:'something', replacement: '../../../something'}, //the initial example
        {find:'somelibrary-1.0.0', replacement: './mylocallibrary-1.5.0'}, //remap a library with a specific version
        {find:/^i18n\!(.*)/, replacement: '$1.js'}, //remove something in front of the import and append an extension (e.g. loaders, for files that were previously transpiled via the AMD module, to properly handle them in rollup as internals now)
        //for whatever reason, replace all .js extensions with .wasm
        {find:/^(.*)\.js$/, replacement: '$1.wasm'}
      ]
    })
  ],
};

// or with object syntax
export default {
  input: './src/index.js',
  plugins: [
    alias({
      resolve: ['.jsx', '.js'],
      entries: {
        something: '../../../something',
        'somelibrary-1.0.0': './mylocallibrary-1.5.0',
      }
    })
  ],
};
```
The order of the entries is important, in that the first rules are applied first.

You can use either simple Strings or Regular Expressions to search in a more distinct and complex manner (e.g. to do partial replacements via subpattern-matching, see aboves example).

## License
MIT, see `LICENSE` for more information

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