![](/img/trans.png)
[英]after upgrade to Webpack 5 not able to access the menifest in copy-webpack-plugin
[英]How to use flatten setting in webpack 5 copy-webpack-plugin
我使用 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? }
那怎么弄呢?
您可以使用[name]
和[ext]
组件在to
参数中设置文件名,并简单地省略path
部分。
plugins: [
new CopyWebpackPlugin({
patterns:[
{
from:'public/js/*.js',
to:path.resolve(__dirname, 'dist','js', '[name][ext]'),
}
]
})
],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.