Closed yaodingyd closed 5 years ago
The issue is happening because you have a shared output.path
. I would highly recommend against this because it can cause other unknown issues.
I'd recommend something like this:
[
{
mode,
entry: {
client: path.join(__dirname, 'src/client/index.js'),
},
output: {
path: path.join(__dirname, 'dist/client/'),
},
plugins: [new CleanWebpackPlugin()],
},
{
mode,
entry: {
server: path.join(__dirname, 'src/server/index.js'),
},
output: {
path: path.join(__dirname, 'dist/server/'),
},
target: 'node',
plugins: [new CleanWebpackPlugin()], // each instance should clean itself
},
];
If you insist on keeping them in the same output.path
, you can try:
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: ['**/*', '!server.js']
});
This will only work if you if your server code will not produce more than one bundle file.
See also: https://github.com/johnagan/clean-webpack-plugin/issues/106 #122 https://github.com/johnagan/clean-webpack-plugin/pull/129
Issue description or question
My webpack config has two entries, client and server, and client build uses CleanWebpackPlugin. When using webpack in
watch
mode, it not only deletes the old output files, but also deletes the newly created server.js file. This issue occur for none watch mode.Interestingly, I added a file watcher using chokidar for dist directory and here is what I found, for no-watch mode:
for watch mode:
Seems like in watch mode CleanWebpackPlugin doesn't really remove old files?
Webpack Config
Environment