一、组件介绍
主要将代码压缩成gzip,目前主流浏览器都支持gzip。
二、安装
npm install compression-webpack-plugin@5.0.1 --save-dev
vue cli 4 webpack打包时会出现 ERROR TypeError:Cannot read property ‘tapPromise‘ of undefined
使用@5.0.1版本就不会有问题。
三、配置
以下是重要配置
//符合断言的进行压缩
test: /\.js$|\.html$|\.css$/,
//对于10K以上的数据进行压缩
threshold: 10240,
//是否删除原始资产
deleteOriginalAssets: false
- test,支持{String|RegExp|Array<String|RegExp>} ,匹配断言
- include 包含
- exclude 不包含
- algorithm 压缩方式 默认为gzip
- threshold 压缩阀值
- filename 压缩生成的名称,默认为[path][base].gz