美文网首页
webpack Error: clean-webpack-pl

webpack Error: clean-webpack-pl

作者: QDzzzhy | 来源:发表于2019-05-05 00:34 被阅读0次

    错误原因

    这是由于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,
    });
    

    相关文章

      网友评论

          本文标题:webpack Error: clean-webpack-pl

          本文链接:https://www.haomeiwen.com/subject/htuqoqtx.html