Closed shirishp closed 6 years ago
did it above worked cause that didnt work for me, as:
{
test: /\.coffee$/
,loader: "string-replace"
,query: {
multiple: [
{
search: new RegExp('@@basepath', 'g')
,replace: '/public'
}
,{
search: new RegExp('@@environment', 'g')
,replace: 'dev'
}
]
}
}
@shirishp any suggestion for me ?whats wrong with my code?
@cdll I can't think of any reason why it wouldn't work. Following thing works in browser console:
"something @@basepath".replace(new RegExp('@@basepath', 'g'), '/public')
// => "something /public"
I would recommend trying to replace something else and see if that string is replaced to confirm this loader is actually triggering.
Configuration
Error:
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:
Notice the multiple array using
search
option as RegExp instead of plain string withoutflags
option.