# rollup-plugin-replace

> [![](https://img.shields.io/npm/v/rollup-plugin-replace.svg?style=flat)](https://www.npmjs.com/package/rollup-plugin-replace)

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

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

## Install

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

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.2.0 |
| Published | 2019-04-10 |
| First published | 2015-10-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 12.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 163 |
| Author | Rich Harris |
| Maintainers | lukastaegert, rich_harris |
| Keywords | rollup, rollup-plugin, es2015, npm, modules |

## Links

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

## Dependencies (2)

- [magic-string](https://npm.io/package/magic-string.md) ^0.25.2
- [rollup-pluginutils](https://npm.io/package/rollup-pluginutils.md) ^2.6.0

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 2.2.0 (latest) — 2019-04-10
- 2.1.1 — 2019-03-18
- 2.1.0 — 2018-10-07
- 2.0.0 — 2017-09-05
- 1.2.1 — 2017-09-05
- 1.1.1 — 2016-06-23
- 1.1.0 — 2015-11-15
- 1.0.1 — 2015-10-26
- 1.0.0 — 2015-10-25

## README

# rollup-plugin-replace
[![](https://img.shields.io/npm/v/rollup-plugin-replace.svg?style=flat)](https://www.npmjs.com/package/rollup-plugin-replace)

Replace strings in files while bundling them.


## Installation

```bash
npm install --save-dev rollup-plugin-replace
```


## Usage

Generally, you need to ensure that rollup-plugin-replace goes *before* other things (like rollup-plugin-commonjs) in your `plugins` array, so that those plugins can apply any optimisations such as dead code removal.


```js
// rollup.config.js
import replace from 'rollup-plugin-replace';

export default {
  // ...
  plugins: [
    replace({
      ENVIRONMENT: JSON.stringify('production')
    })
  ]
};
```


## Options

```js
{
  // a minimatch pattern, or array of patterns, of files that
  // should be processed by this plugin (if omitted, all files
  // are included by default)...
  include: 'config.js',

  // ...and those that shouldn't, if `include` is otherwise
  // too permissive
  exclude: 'node_modules/**',

  // To replace every occurrence of `<@foo@>` instead of every
  // occurrence of `foo`, supply delimiters
  delimiters: ['<@', '@>'],

  // All other options are treated as `string: replacement`
  // replacers...
  VERSION: '1.0.0',
  ENVIRONMENT: JSON.stringify('development'),

  // or `string: (id) => replacement` functions...
  __dirname: (id) => `'${path.dirname(id)}'`,

  // ...unless you want to be careful about separating
  // values from other options, in which case you can:
  values: {
    VERSION: '1.0.0',
    ENVIRONMENT: JSON.stringify('development')
  }
}
```


## Word boundaries

By default, values will only match if they are surrounded by *word boundaries* — i.e. with options like this...

```js
{
  changed: 'replaced'
}
```

...and code like this...

```js
console.log('changed');
console.log('unchanged');
```

...the result will be this:

```js
console.log('replaced');
console.log('unchanged');
```

If that's not what you want, specify empty strings as delimiters:

```js
{
  changed: 'replaced',
  delimiters: ['', '']
}
```



## License

MIT

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