copy-webpack-pluginwebpack 文件拷贝插件
copy-webpack-plugin 可以将已存在的单个文件或整个目录复制到 Webpack 的构建目录。
首先,需要安装copy-webpack-plugin
:
npm install copy-webpack-plugin --save-dev
然后将插件添加到webpack
配置中:
webpack.config.js
const CopyPlugin = require("copy-webpack-plugin");
module.exports = {
plugins: [
new CopyPlugin({
patterns: [
{ from: "source", to: "dest" },
{ from: "other", to: "public" },
],
}),
],
};
- ℹ️
copy-webpack-plugin
并非用于复制在构建过程生成的文件;相反,它是复制源树中已经存在的文件,作为构建过程的一部分。 - ℹ️如果要用
webpack-dev-server
在开发过程中将文件写入输出目录,可以使用writeToDisk
选项或write-file-webpack-plugin
. - ℹ️可以从 Asset Objects 获取原始源文件名。
选项
姓名 | 类型 | 描述 |
---|---|---|
patterns |
{Array<String|Object>} |
为插件指定文件相关模式 |
options |
{Object} |
指定插件选项 |
插件签名:
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, }, }), ], };
评论