avatar

CleanWebpackPlugin is not a constructor

错误信息:

1
2
3
4
5
6
7
TypeError: CleanWebpackPlugin is not a constructor
at Object.<anonymous> (/Users/long/project/front/webpack-demo/webpack.config.js:16:5)
at Module._compile (/Users/long/project/front/webpack-demo/node_modules/_v8-compile-cache@2.0.3@v8-compile-cache/v8-compile-cache.js:192:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1164:10)
at Module.load (internal/modules/cjs/loader.js:993:32)
at Function.Module._load (internal/modules/cjs/loader.js:892:14)
at Module.require (internal/modules/cjs/loader.js:1033:19)

使用方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
const CleanWebpackPlugin = require('clean-webpack-plugin');

module.exports = {
entry: {
app: './src/index.js',
print: './src/print.js'
},
output: {
filename: "[name].bundle.js",
path: path.resolve(__dirname, "dist")
},
plugins: [
new CleanWebpackPlugin(['dist']),
new HtmlWebpackPlugin({
title: 'plugin title'
})
]
};

解决方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

module.exports = {
entry: {
app: './src/index.js',
print: './src/print.js'
},
output: {
filename: "[name].bundle.js",
path: path.resolve(__dirname, "dist")
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
title: 'plugin title'
})
]
};
文章作者: 惆怅客
文章链接: https://www.songhailong.com/articles/87088549/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 惆怅客

评论