一、作用:clean-webpack-plugin插件在webpack打包开始之前,将我们指定的出口文件夹下的文件全部删除;
二、安装:npm install clean-webpack-plugin -D
npm install clean-webpack-plugin -D
三、配置:
1、首先,我们要在webpack的配置文件中引入HtmlWebpackPlugin插件:
// 引入clean-webpack-plugin插件
const CleanWebpackPlugin = require('clean-webpack-plugin')
2、在webpack的配置文件的plugins节点中,创建一个CleanWebpackPlugin的对象;
(1)对于创建的CleanWebpackPlugin对象要不要传递参数,是要看这个插件的版本,我的插件的版本是2.0.1的传递参数必须以一个对象传递,否则会报错;
"devDependencies": {
"autoprefixer": "^9.5.1",
"clean-webpack-plugin": "^2.0.1",
"css-loader": "^2.1.1",
"file-loader": "^3.0.1",
"html-webpack-plugin": "^3.2.0",
"node-sass": "^4.11.0",
"postcss-loader": "^3.0.0",
"sass-loader": "^7.1.0",
"style-loader": "^0.23.1",
"url-loader": "^1.1.2",
"webpack": "^4.30.0",
"webpack-cli": "^3.3.0"
},
这个插件会根据我们的配置文件的output自动去删除出口文件夹下的文件