Open ericxinzhang opened 5 years ago
this plugin can works with webpack dev server: https://github.com/ali322/content-replace-webpack-plugin
const to_replace = [ '__webpack_require__\\(0\\)\\.', '__webpack_require__.' ];
...
new ContentReplacePlugin({
rules: {
'*.js': content => content.replace(new RegExp(to_replace[0],'g'), to_replace[1])
}
})
It took me whole day to find out the cause of this issue as the symptom was very confusing.
My scenario is that I have an environment specific config file stored in source code repo. In webpack.config.js I copy the file to
dist
directory first usingcopy-webpack-plugin
, and then update file content usingreplace-in-file-webpack-plugin
.The file written to dist directory is correct. However somehow webpack dev server never reads the file on disk, but keep returning the original file copied by
copy-webpack-plugin
. I tried the webpack dev server settings likecache
,writeToDisk
, none worked. I am usingwebpack-dev-server
3.2.1, also tried upgrading to latest 3.6.0, both are having this problem.I removed
replace-in-file-webpack-plugin
and used thetransform
incopy-webpack-plugin
, it's working fine now.I am not sure if it's a bug of webpack dev server itself, or there is a way that the plugin can tell webpack dev server some file get updated.