compression-webpack-plugin GZip插件打包报错 ValidationError: Compression Plugin Invalid Options

安装插件: yarn add compression-webpack-plugin
配置webpack.js

const CompressionPlugin = require("compression-webpack-plugin");

return (
	plugins: [
	      new BundleAnalyzerPlugin(),
	      isEnvProduction && new CompressionPlugin({
	        asset: "[path].gz[query]",
	        algorithm: "gzip",
	        test: /\.(js|html)$/,
	        threshold: 10240,
	        minRatio: 0.8
	      }),
	      // ...省略若干行
    ].filter(Boolean),
)

执行后报错:

$ npm run build

> [email protected] build D:\_DATA_\webStormProject\nuistoj
> node scripts/build.js

D:\_DATA_\webStormProject\nuistoj\node_modules\schema-utils\src\validateOptions.js:32
    throw new ValidationError(ajv.errors, name);
    ^

ValidationError: Compression Plugin Invalid Options

options should NOT have additional properties

    at validateOptions (D:\_DATA_\webStormProject\nuistoj\node_modules\schema-utils\src\validateOptions.js:32:11)
    at new CompressionPlugin (D:\_DATA_\webStormProject\nuistoj\node_modules\compression-webpack-plugin\dist\index.js:40:30)
    at module.exports (D:\_DATA_\webStormProject\nuistoj\config\webpack.config.js:475:26)
    at Object.<anonymous> (D:\_DATA_\webStormProject\nuistoj\scripts\build.js:52:16)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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!     C:\Users\Lenovo\AppData\Roaming\npm-cache\_logs\2019-08-19T07_51_57_957Z-debug.log

解决办法:

 // 降版本
 // "compression-webpack-plugin": "^3.0.0",
 // 替换为
 "compression-webpack-plugin": "^1.1.11",

重新执行npm run build即可。

你可能感兴趣的:(React系列)