【问题标题】:How to use flatten setting in webpack 5 copy-webpack-plugin如何在 webpack 5 copy-webpack-plugin 中使用 flatten 设置
【发布时间】:2022-01-10 09:26:29
【问题描述】:

我使用 copy-webpack-plugin 10.2.0 和 webpack 5.65.0。我想将public/js文件夹中的js文件复制到dist/js

plugins: [
    new CopyWebpackPlugin({
        patterns:[
            {
                from:'public/js/*.js',
                to:path.resolve(__dirname, 'dist','js'),
            
            }
        ]
    })
],

但设置也将路径复制到dist中,变成dist/js/public/js。我尝试添加flatten:true,但出现错误

Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
 - options.patterns[0] has an unknown property 'flatten'. These properties are valid:
   object { from, to?, context?, globOptions?, filter?, transformAll?, toType?, force?, priority?, info?, transform?, noErrorOnMissing? }

那要怎么做呢?

【问题讨论】:

    标签: javascript webpack copy-webpack-plugin


    【解决方案1】:

    您可以使用[name][ext] 组件在to 参数中设置文件名,只需省略path 部分。

    plugins: [
        new CopyWebpackPlugin({
            patterns:[
                {
                    from:'public/js/*.js',
                    to:path.resolve(__dirname, 'dist','js', '[name][ext]'),
                
                }
            ]
        })
    ],
    

    【讨论】:

      猜你喜欢
      • 2021-06-18
      • 1970-01-01
      • 2018-03-19
      • 1970-01-01
      • 1970-01-01
      • 2017-07-18
      • 1970-01-01
      • 2022-01-14
      • 2021-05-13
      相关资源
      最近更新 更多