File: README.md

package info (click to toggle)
node-rollup-plugin-replace 2.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 376 kB
  • sloc: makefile: 6; sh: 2
file content (105 lines) | stat: -rw-r--r-- 1,960 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# 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 occurence of `<@foo@>` instead of every
  // occurence 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