引入clean-webpack-plugin重新打包自动删除上次打包的文件以及报错
webpack版本
webpack版本:4.x.x
下载clean-webpack-plugin插件
npm install --save-dev clean-webpack-plugin
const path=require("path");
//重新打包自动删除上次打包的文件
const { CleanWebpackPlugin }=require("clean-webpack-plugin");
module.exports = {
mode:"development",
entry:{
'index':'./src/js/index.js'
},
output:{
path:path.resolve(__dirname,'dist'),
filename:'js/[name].js'
},
module:{
rules:[
{
test:'/\.css$/',
use:[
{
loader:'style-loader',
},
{
loader: 'css-loader',
options: {
modules: true
}
}
]
},{
test:'/\.js$/',
use:[
{
loader:'babel-loader',
options:{
presets:['@babel/preset-dev']
}
}
],
exclude:'/node_module/' // 排除在外
}
]
},
plugins:[
new CleanWebpackPlugin(),
]
}
第一次报错 :CleanWebpackPlugin is not a constructor
我的错误写法
//重新打包自动删除上次打包的文件
const CleanWebpackPlugin =require("clean-webpack-plugin");