如果 webpack 是 v5.20.0+,直接使用属性 output.clean,配置如下:
module.exports = {
//...
output: {
clean: true
},
};
如果使用较低版本,可以使用插件 clean-webpack-plugin:
先安装:npm i clean-webpack-plugin -D;
再配置:
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
module.exports = {
//...
plugins: {
new CleanWebpackPlugin()
},
};