在我们打包时可能需要把files里的文件复制到打包文件夹dist里,该怎么办呢???
很简单,使用copy-webpack-plugin插件轻松解决(参考地址)
安装
npm install copy-webpack-plugin --save-dev
使用
webpack.config.js 文件
const CopyPlugin = require("copy-webpack-plugin");
module.exports = {
plugins: [
new CopyPlugin({
patterns: [
{ from: "source", to: "dest" },
{ from: "other", to: "public" },
],
options: {
concurrency: 100 // 并发数
}
})
]
}
注意:如若出现
compilation.getLogger is not a function问题,解决不了可降低插件版本至5.1.2,使用方法略有不同,如下:
new CopyWebpackPlugin([
{
from: __dirname + "/source",
to: __dirname + "/dest"
}
])