在引入copy-webpack-plugin插件时,运行报错:

Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.


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?, filter?, transformAll?, toType?, force?, priority?, info?, transform?, transformPath?, noErrorOnMissing? }, ...] (should not have fewer than 1 item)
ValidationError: Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
    at validate (/Users/maomao/Documents/demo/h5/mm_webpack/node_modules/schema-utils/dist/validate.js:104:11)

原配置如下:

let CopyWebpackPlugin = require("copy-webpack-plugin")

module.exports = {
    new CopyWebpackPlugin([
      {
        from: "./doc",//源路径
        to: "./doc",//目标路径
      }
    ])
}

报错原因:

新版本的webpack的配置形式变更了。

解决办法:

更新配置为:

let CopyWebpackPlugin = require("copy-webpack-plugin")

module.exports = {
    new CopyWebpackPlugin({
      patterns: [{
        from: "./doc",//源路径
        to: "./doc",//目标路径
      }]
    })
}

运行检查:

npm run build