rollup-plugin-replace2.1.1 • Public • Published
Replace strings in files while bundling them.
npm install --save-dev rollup-plugin-replace
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.
// rollup.config.js;// ...plugins:;
// 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 permissiveexclude: 'node_modules/**'// To replace every occurence of `<@foo@>` instead of every// occurence of `foo`, supply delimitersdelimiters: '<@' '@>'// All other options are treated as `string: replacement`// replacers...VERSION: '1.0.0'ENVIRONMENT: JSON// or `string: (id) => replacement` functions...`''`// ...unless you want to be careful about separating// values from other options, in which case you can:values:VERSION: '1.0.0'ENVIRONMENT: JSON
By default, values will only match if they are surrounded by word boundaries — i.e. with options like this...
...and code like this...
...the result will be this:
If that's not what you want, specify empty strings as delimiters:
changed: 'replaced'delimiters: '' ''