webpack使用copy-webpack-plugin插件遇到错误:Invalid options object. Copy Plugin has been initialized using an

使用copy-webpack-plugin插件遇到的报错:

Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
-options[0] misses the property ‘patterns’. Should be:
[non-empty string | object { from, to?, context?, globOptions?, toType?, force?, flatten?, transform?, cacheTransform?, transformPath?, noErrorOnMissing? }, …] (should not have fewer than 1 item)

在学习webpack时,我们通常这样使用该插件:

const CopyWebpackPlugin = require("copy-webpack-plugin");

module.exports = {
  entry: "./src/index.js",
  output: {
    filename: "bundle.js",
  },
  plugins: [
    new CopyWebpackPlugin([
    { from: "public" }
    ]),
  ],
};

这样就能使得根目录下的public文件复制到dist输出文件中,但这样使用会报错:
webpack使用copy-webpack-plugin插件遇到错误:Invalid options object. Copy Plugin has been initialized using an_第1张图片

在这里我的解决方法是:
修改copy-webpack-plugin的对象

const CopyWebpackPlugin = require("copy-webpack-plugin");

module.exports = {
  mode: "development",
  entry: "./src/text.js",
  output: {
    filename: "bundle.js",
  },
  plugins: [
    new CopyWebpackPlugin(
      { patterns: [{ from: "public", to: "public" }] } // 需要拷贝的目录或者路径通配符
    ),
  ],
};

webpack使用copy-webpack-plugin插件遇到错误:Invalid options object. Copy Plugin has been initialized using an_第2张图片
打包完成并复制了静态文件。

你可能感兴趣的:(webpack)