webpack Error: clean-webpack-plugin only accepts an options object

错误原因

这是由于clean-webpack-plugin版本问题导致的,在2.0.0以上的版本中,对clean-webpack-plugin的使用有了一定的变化

具体使用
  • 在2.0.0版本以前,也就是1.x版本中,官方文档指示的配置是这样的
plugins: [
    new CleanWebpackPlugin(paths [, {options}])
 ]

也就是大多数视频中提到的传入一个数组,指定要删除的目录,但在我们跟着做的过程中就会报标题中的那个错误

  • 在2.x版本以后,官方对它的使用进行了修改
plugins: [
    // See Options and Defaults
    new CleanWebpackPlugin()
],
  • 可以看到去掉了复杂的参数,直接new即可使用
  • 当然里面仍然可以配置,但是只能传入一个对象配置,无法再在第一个参数传入数组指定删除目录
new CleanWebpackPlugin({
    // Simulate the removal of files	 
    //
    // default: false
    dry: true,
 
    // Write Logs to Console
    // (Always enabled when dry is true)
    //
    // default: false
    verbose: true,
 
    // Automatically remove all unused webpack assets on rebuild
    //
    // default: true
    cleanStaleWebpackAssets: false,
 
    // Do not allow removal of current webpack assets
    //
    // default: true
    protectWebpackAssets: false,
 
    // **WARNING**
    //
    // Notes for the below options:
    //
    // They are unsafe...so test initially with dry: true.
    //
    // Relative to webpack's output.path directory.
    // If outside of webpack's output.path directory,
    //    use full path. path.join(process.cwd(), 'build/**/*')
    //
    // These options extend del's pattern matching API.
    // See https://github.com/sindresorhus/del#patterns
    //    for pattern matching documentation
 
    // Removes files once prior to Webpack compilation
    //   Not included in rebuilds (watch mode)
    //
    // Use !negative patterns to exclude files
    //
    // default: ['**/*']
    cleanOnceBeforeBuildPatterns: ['**/*', '!static-files*'],
    cleanOnceBeforeBuildPatterns: [], // disables cleanOnceBeforeBuildPatterns
 
    // Removes files after every build (including watch mode) that match this pattern.
    // Used for files that are not created directly by Webpack.
    //
    // Use !negative patterns to exclude files
    //
    // default: disabled
    cleanAfterEveryBuildPatterns: ['static*.*', '!static1.js'],
 
    // Allow clean patterns outside of process.cwd()
    //
    // requires dry option to be explicitly set
    //
    // default: false
    dangerouslyAllowCleanPatternsOutsideProject: true,
    dry: true,
});
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值