Replace content in file in webpack workflow
$ npm i webpack-content-replacer-plugin
Note: This plugin needs NodeJS >= 6
Require webpack-content-replacer-plugin
var ContentReplacer = require('webpack-content-replacer-plugin')
Add the plugin to your plugin list
var config = {
plugins: [
new ContentReplacer({
modifiedFile: './relative_path/file_to_be_modified.ext',
modifications: [
{
regex: /%content_to_be_deleted%/g,
modification: 'new_content',
},
{
regex: /%content2_to_be_deleted%/g,
modification: 'new_content2',
},
],
})
]
}
silent
(bool): Display/hide info logsmodifiedFile
(string): File to be modifiedmodifications
(string): Array of modifications' object having regex and modification propertybuildTrigger
(string): Webpack build step (c.f plugin documentation). See below accepted steps:after-emit
done
failed
Call at specific step
var config = {
plugins: [
new ContentReplacer({
buildTrigger: 'after-emit',
modifiedFile: './relative_path/file_to_be_modified.ext',
modifications: [
{
regex: /%content_to_be_deleted%/g,
modification: 'new_content',
},
{
regex: /%content2_to_be_deleted%/g,
modification: 'new_content2',
},
],
})
]
}
Use silent mode
var config = {
plugins: [
new ContentReplacer({
silent: true,
modifiedFile: './relative_path/file_to_be_modified.ext',
modifications: [
{
regex: /%content_to_be_deleted%/g,
modification: 'new_content',
},
{
regex: /%content2_to_be_deleted%/g,
modification: 'new_content2',
},
],
})
]
}
All contributions are welcome. Please make a pull request and make sure things still pass after running npm test