webpack.config.prod.js报错原因是啥?

来源:2-13 koa应用打包优化koa-compose&koa-compress 【实战篇】

慕运维7587644

2019-10-19 00:49:34

const webpackMerge = require('webpack-merge');


const baseWebpackConfig = require('./webpack.config.base');

// 类似于uglify 压缩文件

const TerserWebpackPlugin = require('terser-webpack-plugin');



const webpackConfig = webpackMerge(baseWebpackConfig, {

mode: 'production',

stats: {children: false, warnings:false},

optimization: {

minimizer: [

new TerserWebpackPlugin({

terserOptions: {

warnings: false,

compress: {

warnings: false,

drop_console: false,

dead_code: true,

drop_debugger: true

},

output: {

comments: false,

beautify: false

},

mangle: true, // Note `mangle.properties` is `false` by default.

},

parallel: true,

sourceMap: false

})

],

splitChunks: {

cacheGroups: {

commons: {

name: "commons",

chunks: "initial",

minChunks: 3,

enforce: true

}

}

}

}

})


module.exports = webpackConfig;


报错:

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.

 - configuration has an unknown property 'plugin'. These properties are valid:

   object { amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry?, externals?, infrastructureLogging?, loader?, mode?, module?, name?, node?, optimization?, output?, parallelism?, performance?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, serve?, stats?, target?, watch?, watchOptions? }

   For typos: please correct them.

   For loader options: webpack >= v2.0.0 no longer allows custom properties in configuration.

     Loaders should be updated to allow passing options via loader options in module.rules.

     Until loaders are updated one can use the LoaderOptionsPlugin to pass these options to the loader:

     plugins: [

       new webpack.LoaderOptionsPlugin({

         // test: /\.xxx$/, // may apply this only for some modules

         options: {

           plugin: …

         }

       })

     ]

npm ERR! code ELIFECYCLE

npm ERR! errno 1

npm ERR! koa@1.0.0 build: `cross-env NODE_ENV=prod webpack --config config/webpack.config.prod.js`

npm ERR! Exit status 1

npm ERR! 

npm ERR! Failed at the koa@1.0.0 build script.

npm ERR! This is probably not a problem with npm. There is likely additional logging output above.


npm ERR! A complete log of this run can be found in:

npm ERR!     /Users/dongdong/.npm/_logs/2019-10-18T16_30_58_418Z-debug.log

dongdongdeMacBook-Pro:koa dongdong$ npm run build


> koa@1.0.0 build /Users/dongdong/前端知识扩展/koa

> cross-env NODE_ENV=prod webpack --config config/webpack.config.prod.js


Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.

 - configuration has an unknown property 'plugin'. These properties are valid:

   object { amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry?, externals?, infrastructureLogging?, loader?, mode?, module?, name?, node?, optimization?, output?, parallelism?, performance?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, serve?, stats?, target?, watch?, watchOptions? }

   For typos: please correct them.

   For loader options: webpack >= v2.0.0 no longer allows custom properties in configuration.

     Loaders should be updated to allow passing options via loader options in module.rules.

     Until loaders are updated one can use the LoaderOptionsPlugin to pass these options to the loader:

     plugins: [

       new webpack.LoaderOptionsPlugin({

         // test: /\.xxx$/, // may apply this only for some modules

         options: {

           plugin: …

         }

       })

     ]

npm ERR! code ELIFECYCLE

npm ERR! errno 1

npm ERR! koa@1.0.0 build: `cross-env NODE_ENV=prod webpack --config config/webpack.config.prod.js`

npm ERR! Exit status 1

npm ERR! 

npm ERR! Failed at the koa@1.0.0 build script.

npm ERR! This is probably not a problem with npm. There is likely additional logging output above.


npm ERR! A complete log of this run can be found in:

npm ERR!     /Users/dongdong/.npm/_logs/2019-10-18T16_33_02_798Z-debug.log


写回答

1回答

Brian

2019-10-20

提示是说plugin属性不对,你检查一下格式。


同学有没有GitHub地址呀?错误截图呀?


下次提问,可以提供包括且不限于:
1. webpack版本,vue版本,node版本,npm版本。
2. webpack配置;
3. package.json
4. 本课程中的哪个实例操作出如上的错误,操作的流程是什么?!
5. 代码截图,console错误截图,终端错误截图。
分享自己解决问题的经过,加强对问题的解决能力。
这样才能更好的帮助到大家哦

0

0 学习 · 1842 问题

查看课程