How difficult would it be to make this plugin run on multiple files?
Closed this issue · 2 comments
I'm trying to use it to mass-replace some references in a number of files, but it seems like it only runs on the first one.
Hmm... have you tried something like this?
var StringReplacePlugin = require("string-replace-webpack-plugin");
module.exports = {
module: {
loaders: [
// configure replacements for file patterns
{ test: /index.html$/, loader: StringReplacePlugin.replace({
replacements: [
{
pattern: /<!-- @secret (\w*?) -->/ig,
replacement: function (match, p1, offset, string) {
return secrets.web[p1];
}
}
]})
},
{ test: /*.js$/, loader: StringReplacePlugin.replace({
replacements: [
{
pattern: /<!-- @secret (\w*?) -->/ig,
replacement: function (match, p1, offset, string) {
return secrets.web[p1];
}
}
]})
}
]
},
plugins: [
// an instance of the plugin must be present
new StringReplacePlugin()
]
}
Each call to replace()
should capture the options passed into it. From there the webpack plugin infrastructure should be passing any file that matches the test
pattern and invoking the plugin with the settings that are passed to the replace()
function for that pattern.
Ah, nevermind — I see what I was doing wrong. I was trying to update a variable on both a root .sass file and an @imported one, but the import doesn't happen until sass compilation, so only one file was getting run through your plugin in the first place. Looks like I would need to do sass comp first, then your plugin, then the rest of my CSS loaders. Thanks!