|
package.json中下载的包版本,如下:
"devDependencies": {
"clean-webpack-plugin": "^3.0.0",
"html-webpack-plugin": "^3.2.0",
"webpack": "^4.36.1",
"webpack-cli": "^3.3.6"
}在项目中引入clean-webpack-plugin打包后报错 new CleanWebpackPlugin(), ^TypeError: CleanWebpackPlugin is not a constructor 项目写法: 引入: cnpm i clean-webpack-plugin -Dwebpack.config.js中, const CleanWebpackPlugin = require('clean-webpack-plugin')
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
filename: 'index.html',
template: './src/index.html'
})
],看了一下githup上的写法,现在新版本的clean-webpack-plugin引入已经改为 const { CleanWebpackPlugin } = require('clean-webpack-plugin'); 所以修改引入写法就OK了 const {CleanWebpackPlugin} = require('clean-webpack-plugin')
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
filename: 'index.html',
template: './src/index.html'
})
],改变了引入方式后,就可以正常运行了。参考:https://www.cnblogs.com/steamed-twisted-roll/p/10990309.html |
|
|