reactjs - CopyWebpackPlugin 到 react webpack 应用程序中的 dist 文件夹
问题描述
我尝试使用 CopyWebpackPlugin 将 src 中的图像文件夹复制到根 dist 文件夹,但出现以下错误:
ValidationError:无效的选项对象。Copy Plugin 已使用与 API 模式不匹配的选项对象进行初始化。
- options[0] 缺少属性“模式”。应该是:[非空字符串 | object { from, to?, context?, globOptions?, filter?, toType?, force?, priority?, info?, transform?, transformPath?, noErrorOnMissing? }, ...](不应少于 1 项)
(插件我试图使用) - https://webpack.js.org/plugins/copy-webpack-plugin/
webpack.config.js 如下:
const path = require("path");
const htmlWebpackPlugin = require("html-webpack-plugin");
const pathName = path.resolve(__dirname, "./src");
const entry = path.resolve(__dirname, "./src/index.js");
const Dotenv = require("dotenv-webpack");
const CopyWebpackPlugin = require("copy-webpack-plugin");
console.log("path is", pathName, entry);
module.exports = {
devServer: {
contentBase: pathName,
historyApiFallback: true,
},
entry: entry,
module: {
rules: [
{
test: /\.jsx?$/,
use: "babel-loader",
},
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env", "@babel/preset-react"],
plugins: [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-runtime",
],
//npm install --save-dev @babel/plugin-transform-runtime
},
},
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"],
},
{
test: /\.(png|jpe?g|gif)$/i,
use: [
{
loader: "file-loader",
},
],
},
],
},
output: {
filename: "bundle.js",
},
plugins: [
new htmlWebpackPlugin({
filename: "index.html",
template: path.resolve(__dirname, "./src/index.html"),
}),
new Dotenv(),
new CopyWebpackPlugin({
patterns: [{ from: "src/images", to: "images" }],
}),
],
};
解决方案
推荐阅读
- python - Windows 根据 PDF 文件本身的信息自动命名
- javascript - 将自制库导入vue项目
- sql-server-2008 - 在 SSRS 2008 中,如何在文本框中同时显示多值参数的标签和值?
- javascript - 如何编写 Javascipt 代码为任何字符串的输入创建小于或等于 20 字节的哈希字符串?
- python - 在 python 3 中使用 xor 计算校验和
- java - Hibernate级联删除依赖实体(ManyToOne OneToMany)
- python-3.x - 如何将列表分成嵌套列表,列表中所有元素的平均值?
- amazon-web-services - AWS RDS pg_transport 未能下载文件数据
- react-native - 在本机反应上获取错误网络但在邮递员上工作
- extjs - ExtJS7:锚标记不遵守 ext 路由