@rollup/plugin-replace
[cover]: https://codecov.io/gh/rollup/plugins/branch/master/graph/badge.svg [cover-url]: https://codecov.io/gh/rollup/plugins [size]: https://packagephobia.now.sh/badge?p=@rollup/plugin-replace [size-url]: https://packagephobia.now.sh/result?p=@rollup/plu
Last updated 10 days ago by rich_harris .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @rollup/plugin-replace 
SYNC missed versions from official npm registry.

tests cover size libera manifesto

@rollup/plugin-replace

???? A Rollup which replaces strings in files while bundling.

Requirements

This plugin requires an LTS Node version (v8.0.0+) and Rollup v1.20.0+.

Install

Using npm:

npm install @rollup/plugin-replace --save-dev

Usage

Create a rollup.config.js configuration file and import the plugin:

import replace from '@rollup/plugin-replace';

export default {
  input: 'src/index.js',
  output: {
    dir: 'output',
    format: 'cjs'
  },
  plugins: [replace({ __buildEnv__: 'production' })]
};

Then call rollup either via the CLI or the API.

The configuration above will replace every instance of __buildEnv__ with 'productions' in any file included in the build. Note: Values should always be strings. For complex values, use JSON.stringify.

Typically, @rollup/plugin-replace should be placed in plugins before other plugins so that they may apply optimizations, such as dead code removal.

Options

In addition to the properties and values specified for replacement, users may also specify the options below.

delimiters

Type: Array[String, String] Default: ['\b', '\b']

Specifies the boundaries around which strings will be replaced. By default, delimiters are word boundaries. See Word Boundaries below for more information.

exclude

Type: String | Array[...String] Default: null

A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should ignore. By default no files are ignored.

include

Type: String | Array(String) Default: null

A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should operate on. By default all files are targeted.

Word Boundaries

By default, values will only match if they are surrounded by word boundaries.

Consider the following options and build file:

module.exports = {
  ...
  plugins: [replace({ changed: 'replaced' })]
};
// file.js
console.log('changed');
console.log('unchanged');

The result would be:

// file.js
console.log('replaced');
console.log('unchanged');

To ignore word boundaries and replace every instance of the string, wherever it may be, specify empty strings as delimiters:

export default {
  ...
  plugins: [
    replace({
      changed: 'replaced',
      delimiters: ['', '']
    })
  ]
};

Meta

CONTRIBUTING

LICENSE (MIT)

Current Tags

  • 2.2.1                                ...           latest (10 days ago)

2 Versions

  • 2.2.1                                ...           10 days ago
  • 2.2.0                                ...           19 days ago

Copyright 2014 - 2016 © taobao.org |