Replace content while bundling.
Install
$ npm install --save-dev webpack-plugin-replace
Usage
// webpack.config.jsconst ReplacePlugin = ; moduleexports = // ... plugins: exclude: 'foo.js' /node_modules/ filepath patterns: regex: /throw\s+??Error\s*\(/g value: 'return;(' values: 'process.env.NODE_ENV': JSON 'FOO_BAR': '"hello world"' 'DEV_MODE': false ;
API
webpack-plugin-replace(options)
options.exclude
Type: Array|String|Function|RegExp
Default: false
If multiple conditions are provided, matching any condition will exclude the filepath, which prevents any alterations.
Note: By default, nothing is excluded!
options.include
Type: Array|String|Function|RegExp
Default: true
If multiple conditions are provided, matching any condition will include & scan the filepath for eligible replacements.
Note: By default, all filepaths are included!
options.patterns
Type: Array
Default: []
An array of RegExp
pattern definitions. Each definition is an object with regex <RegExp>
and value <String|Function>
keys. If value
is a function, it takes the same arguments as String.prototype.relace
.
options.values
Type: Object
Default: {}
An object whose keys are strings
that should be replaced and whose values are strings
the replacements.
If desired, you may forgo the values
key & declare your key:value
pairs directly to the main configuration. For example:
exclude: /node_modules/ values: 'process.env.NODE_ENV': JSON // is the same as: exclude: /node_modules/ 'process.env.NODE_ENV': JSON
License
MIT © Luke Edwards