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

copy-webpack-plugin运行报错误


最近在安装使用webpack的copy-webpack-plugin 拷贝插件的时候,报了一些错误:
错误详见下面代码,没有粘贴完, 大概意思就是Copy Plugin的初始化对象不正确,查看了官网也没有看出所以然,最后在npm官网上找打了原因
错误配置:

  new CopyWebpackPlugin([
            {
                // from:path.join(__dirname,'assets'),
                // to:'assets'
            }

        ])

怎么看都没有错误
最后参看一下这个npn官网找打了原因,地址:https://www.npmjs.com/package/copy-webpack-plugin
更改正确的写法:

 new CopyWebpackPlugin({
            patterns: [
                { from: path.join(__dirname,'assets'),
                    to: 'assets' }
            ],
        }),

只不过比之前多了一个 patterns[]
官网上介绍了很多的写法,找到适合自己的项目结构,更改一下即可

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?, cacheTran
sform?, 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 mat
ch the API schema.
    at validate (D:\myproject\myweb\node_modules\copy-webpack-plugin\node_modules\schema-utils\dist\validate.js:88:
11)
    at new CopyPlugin (D:\myproject\myweb\node_modules\copy-webpack-plugin\dist\index.js:24:30)
    at Object. (D:\myproject\myweb\webpack.config.js:43:9)
    at Module._compile (D:\myproject\myweb\node_modules\v8-compile-cache\v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)

你可能感兴趣的:(webpack,node.js)