-
Notifications
You must be signed in to change notification settings - Fork 56
Closed
Description
Configuration
module.exports = {
// ...
module: {
loaders: [
{
test: /\.js$/,
loader: 'string-replace',
query: {
multiple: [
{ search: '{vars.id}', replace: '90', flags: 'g' },
{ search: '{path.api}', replace: 'http://localhost:9000', flags: 'g'}
]
}
}
]
}
}
Error:
WARNING in <file_name>
Module build failed: TypeError: Cannot supply flags when constructing one RegExp from another
at new RegExp (native)
at processOptions (node_modules/string-replace-loader/index.js:8:24)
at node_modules/string-replace-loader/index.js:31:16
at Array.forEach (native)
at Object.module.exports (node_modules/string-replace-loader/index.js:29:22)
@ ./src/javascript/scripts \.js$
This seems to be happening because https://github.com/Va1/string-replace-loader/blob/master/index.js#L29 returns source as regular expression, and then the regular expression is again passed to RegEx constructor at https://github.com/Va1/string-replace-loader/blob/master/index.js#L7
Workaround
For now, changing the configuration to following seems to work:
module.exports = {
// ...
module: {
loaders: [
{
test: /\.js$/,
loader: 'string-replace',
query: {
multiple: [
{ search: new RegExp('{vars.id}', 'g'), replace: '90'},
{ search: new RegExp('{path.api}', 'g'), replace: 'http://localhost:9000'}
]
}
}
]
}
}
Notice the multiple array using search
option as RegExp instead of plain string without flags
option.
syuilo
Metadata
Metadata
Assignees
Labels
No labels