A webpack loader to replace a regexp pattern with a string
npm install regexp-replace-loader
// webpack.config.js
...
module: {
rules: [
{
test: /\.js$/,
loader: 'regexp-replace-loader',
options: {
match: {
pattern: 'ba(r|z)',
flags: 'g'
},
replaceWith: 'foo'
}
}
]
}
// webpack.config.js
...
module: {
loaders: [
{
test: /\.js$/,
loader: 'regexp-replace-loader',
query: {
match: {
pattern: 'ba(r|z)',
flags: 'g'
},
replaceWith: 'foo'
}
}
]
}
All instances of "bar" and "baz" will then be replaced by "foo".