1、出错代码 const path = require('path')const CleanWebpackPlugin = require('clean-webpack-plugin')// const { CleanWebpackPlugin } = require('clean-webpack-plugin')module.exports = { entry: './input.js', output: { path: path.resolve(__d
1、出错代码
const path = require('path') const CleanWebpackPlugin = require('clean-webpack-plugin') // const { CleanWebpackPlugin } = require('clean-webpack-plugin') module.exports = { entry: './input.js', output: { path: path.resolve(__dirname, 'dist'), filename: 'output.bundle.js' }, mode: 'development', plugins: [ new CleanWebpackPlugin() ], module: { rules: [ { test: /\.(png|jpg|gif)$/i, use: [ { loader: 'url-loader', options: { // limit: 8192 // 说明小于8192字节也就是8k才会执行 limit: 919200 } } ] } ] } }
2、错误描述
[webpack-cli] TypeError: CleanWebpackPlugin is not a constructor
3、出错原因
导入插件语句有误,以及使用有误
4、解决
应改为如下导入语句:
const { CleanWebpackPlugin } = require('clean-webpack-plugin') // es modules import { CleanWebpackPlugin} from 'clean-webpack-plugin';
而在使用时也是,如果都是默认清空dist文件下下的内容的话,默认不需要写参数。
和默认删除目录不同时才需要传入路径,且需要通过选项`cleanOnceBeforeBuildPatterns`来传入。
参考 【clean-webpack-plugin】
到此这篇关于详解webpack的clean-webpack-plugin插件报错的文章就介绍到这了,更多相关webpack clean-webpack-plugin插件内容请搜索易盾网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持易盾网络!