npm i -D clean-webpack-plugin
当hash值改变的时候,不用手动删除文件:
webpack.config:
var { CleanWebpackPlugin } = require("clean-webpack-plugin")
module.exports = {
mode: "development",
devtool: "source-map",
output: {
filename: "[name].[chunkhash:5].js"
},
plugins: [
new CleanWebpackPlugin() //原理:当emit的时候,用fs模块删除dist目录
]
}