CleanWebpackPlugin is not a constructor

本文解决了一个在使用CleanWebpackPlugin时遇到的“CleanWebpackPlugin is not a constructor”错误。通过对比新旧用法,指出了官方文档变更导致的问题,并给出了正确的配置示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

webpack报错

今天初始化项目时,报了这个一个错
CleanWebpackPlugin is not a constructor,刚开始以为是包下载的问题,重装后发现还是出现这样的问题,翻了官方文档发现用法变了,而中文文档还没有更新过来。
之前的用法
const path = require(‘path’);
const HtmlWebpackPlugin = require(‘html-webpack-plugin’);

  • const CleanWebpackPlugin = require(‘clean-webpack-plugin’);

    module.exports = {
    entry: {
    app: ‘./src/index.js’,
    print: ‘./src/print.js’
    },
    plugins: [

  • new CleanWebpackPlugin(['dist']),
    new HtmlWebpackPlugin({
      title: 'Output Management'
    })
    

    ],
    output: {
    filename: ‘[name].bundle.js’,
    path: path.resolve(__dirname, ‘dist’)
    }
    };

现在的用法
const { CleanWebpackPlugin } = require(‘clean-webpack-plugin’);

const webpackConfig = {
plugins: [
/**
* All files inside webpack’s output.path directory will be removed once, but the
* directory itself will not be. If using webpack 4+'s default configuration,
* everything under <PROJECT_DIR>/dist/ will be removed.
* Use cleanOnceBeforeBuildPatterns to override this behavior.
*
* During rebuilds, all webpack assets that are not used anymore
* will be removed automatically.
*
* See Options and Defaults for information
*/
new CleanWebpackPlugin(),
],
};

module.exports = webpackConfig;

作者:骨朵a
链接:https://www.jianshu.com/p/0e99366ce796
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值