source: frontend/node_modules/@rollup/plugin-replace/README.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 4.7 KB
Line 
1[npm]: https://img.shields.io/npm/v/@rollup/plugin-replace
2[npm-url]: https://www.npmjs.com/package/@rollup/plugin-replace
3[size]: https://packagephobia.now.sh/badge?p=@rollup/plugin-replace
4[size-url]: https://packagephobia.now.sh/result?p=@rollup/plugin-replace
5
6[![npm][npm]][npm-url]
7[![size][size]][size-url]
8[![libera manifesto](https://img.shields.io/badge/libera-manifesto-lightgrey.svg)](https://liberamanifesto.com)
9
10# @rollup/plugin-replace
11
12🍣 A Rollup plugin which replaces targeted strings in files while bundling.
13
14## Requirements
15
16This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v8.0.0+) and Rollup v1.20.0+.
17
18## Install
19
20Using npm:
21
22```console
23npm install @rollup/plugin-replace --save-dev
24```
25
26## Usage
27
28Create a `rollup.config.js` [configuration file](https://www.rollupjs.org/guide/en/#configuration-files) and import the plugin:
29
30```js
31import replace from '@rollup/plugin-replace';
32
33export default {
34 input: 'src/index.js',
35 output: {
36 dir: 'output',
37 format: 'cjs'
38 },
39 plugins: [
40 replace({
41 'process.env.NODE_ENV': JSON.stringify('production'),
42 __buildDate__: () => JSON.stringify(new Date()),
43 __buildVersion: 15
44 })
45 ]
46};
47```
48
49Then call `rollup` either via the [CLI](https://www.rollupjs.org/guide/en/#command-line-reference) or the [API](https://www.rollupjs.org/guide/en/#javascript-api).
50
51The configuration above will replace every instance of `process.env.NODE_ENV` with `"production"` and `__buildDate__` with the result of the given function in any file included in the build.
52
53_Note: Values must be either primitives (e.g. string, number) or `function` that returns a string. For complex values, use `JSON.stringify`. To replace a target with a value that will be evaluated as a string, set the value to a quoted string (e.g. `"test"`) or use `JSON.stringify` to preprocess the target string safely._
54
55Typically, `@rollup/plugin-replace` should be placed in `plugins` _before_ other plugins so that they may apply optimizations, such as dead code removal.
56
57## Options
58
59In addition to the properties and values specified for replacement, users may also specify the options below.
60
61### `delimiters`
62
63Type: `Array[...String, String]`<br>
64Default: `['\b', '\b']`
65
66Specifies the boundaries around which strings will be replaced. By default, delimiters are [word boundaries](https://www.regular-expressions.info/wordboundaries.html). See [Word Boundaries](#word-boundaries) below for more information.
67
68### `preventAssignment`
69
70Type: `Boolean`<br>
71Default: `false`
72
73Prevents replacing strings where they are followed by a single equals sign. For example, where the plugin is called as follows:
74
75```js
76replace({
77 values: {
78 'process.env.DEBUG': 'false'
79 }
80});
81```
82
83Observe the following code:
84
85```js
86// Input
87process.env.DEBUG = false;
88if (process.env.DEBUG == true) {
89 //
90}
91// Without `preventAssignment`
92false = false; // this throws an error because false cannot be assigned to
93if (false == true) {
94 //
95}
96// With `preventAssignment`
97process.env.DEBUG = false;
98if (false == true) {
99 //
100}
101```
102
103### `exclude`
104
105Type: `String` | `Array[...String]`<br>
106Default: `null`
107
108A [minimatch pattern](https://github.com/isaacs/minimatch), or array of patterns, which specifies the files in the build the plugin should _ignore_. By default no files are ignored.
109
110### `include`
111
112Type: `String` | `Array[...String]`<br>
113Default: `null`
114
115A [minimatch pattern](https://github.com/isaacs/minimatch), or array of patterns, which specifies the files in the build the plugin should operate on. By default all files are targeted.
116
117### `values`
118
119Type: `{ [key: String]: Replacement }`, where `Replacement` is either a string or a `function` that returns a string.
120Default: `{}`
121
122To avoid mixing replacement strings with the other options, you can specify replacements in the `values` option. For example, the following signature:
123
124```js
125replace({
126 include: ['src/**/*.js'],
127 changed: 'replaced'
128});
129```
130
131Can be replaced with:
132
133```js
134replace({
135 include: ['src/**/*.js'],
136 values: {
137 changed: 'replaced'
138 }
139});
140```
141
142## Word Boundaries
143
144By default, values will only match if they are surrounded by _word boundaries_.
145
146Consider the following options and build file:
147
148```js
149module.exports = {
150 ...
151 plugins: [replace({ changed: 'replaced' })]
152};
153```
154
155```js
156// file.js
157console.log('changed');
158console.log('unchanged');
159```
160
161The result would be:
162
163```js
164// file.js
165console.log('replaced');
166console.log('unchanged');
167```
168
169To ignore word boundaries and replace every instance of the string, wherever it may be, specify empty strings as delimiters:
170
171```js
172export default {
173 ...
174 plugins: [
175 replace({
176 changed: 'replaced',
177 delimiters: ['', '']
178 })
179 ]
180};
181```
182
183## Meta
184
185[CONTRIBUTING](/.github/CONTRIBUTING.md)
186
187[LICENSE (MIT)](/LICENSE)
Note: See TracBrowser for help on using the repository browser.