1. npm i -D clean-webpack-plugin

    当hash值改变的时候,不用手动删除文件:
    webpack.config:

    1. var { CleanWebpackPlugin } = require("clean-webpack-plugin")
    2. module.exports = {
    3. mode: "development",
    4. devtool: "source-map",
    5. output: {
    6. filename: "[name].[chunkhash:5].js"
    7. },
    8. plugins: [
    9. new CleanWebpackPlugin() //原理:当emit的时候,用fs模块删除dist目录
    10. ]
    11. }