3

我使用 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? }

那怎么弄呢?

4

1 回答 1

1

您可以使用和组件在to参数中设置文件名,并简单地省略该部分。[name][ext]path

plugins: [
    new CopyWebpackPlugin({
        patterns:[
            {
                from:'public/js/*.js',
                to:path.resolve(__dirname, 'dist','js', '[name][ext]'),
            
            }
        ]
    })
],
于 2022-01-10T15:39:55.827 回答