1. npm i clean-webpack-plugin --save-dev
2. 使用
~~~
//webpack.config.js
const path = require('path');
const htmlWebpackPlugin = require('html-webpack-plugin');
const cleanWebpackPlugin = require('clean-webpack-plugin'); //++
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[hash].bundle.js'
//或者[name].bundle.js
},
plugins:[
new cleanWebpackPlugin(['dist']), //++
new htmlWebpackPlugin({
title:"打包文件",
inject:"head",
template:"index.html",
filename:'[hash]-index.html'
})
]
};
~~~