javascript - How to use flatten setting in webpack 5 copy-webpack-plugin - Stack Overflow

I use copy-webpack-plugin 10.2.0 and webpack 5.65.0. I want to copy js file in publicjs folder to dist

I use copy-webpack-plugin 10.2.0 and webpack 5.65.0. I want to copy js file in public/js folder to dist/js.

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

But the setting also copy the path into dist, and it bees dist/js/public/js.I try to add flatten:true but it has error

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? }

How to make it then ?

I use copy-webpack-plugin 10.2.0 and webpack 5.65.0. I want to copy js file in public/js folder to dist/js.

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

But the setting also copy the path into dist, and it bees dist/js/public/js.I try to add flatten:true but it has error

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? }

How to make it then ?

Share Improve this question asked Jan 10, 2022 at 9:26 RyanRyan 20.2k10 gold badges43 silver badges64 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

You can set the filename in the to parameter using the [name] and [ext] ponents and simply omit the path part.

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745076977a4609893.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信