作用
在项目每次build之前删除相对应的文件 参考文章
下载依赖
npm i clean-webpack-plugin -D
文件配置
const path = require('path')
const htmlWebpackPlugin = require('html-webpack-plugin')
// 在node_module---clean-webpack-plugin下查看导出方式已经改成这样
const CleanWebpackPlugin = require('clean-webpack-plugin') //webpack4.0以上会报错
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
module.exports = {
entry: {
app: './src/index'
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name]:[hash:6].js'
},
plugins: [
new htmlWebpackPlugin(),
// 也可以不用配置
// new CleanWebpackPlugin()
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: [
// 每次build如果文件有改动会自动删除之前的文件
path.resolve(__dirname, 'dist'),
]
})
],
mode: 'development'
}