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 ?
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]'),
}
]
})
],