安装版本号
版本7.0.0
配置如下
const CompressionWebpackPlugin = require("compression-webpack-plugin")
const isProduction = process.env.NODE_ENV === 'production';
configureWebpack: config => {
if (isProduction) {
//gzip压缩
const productionGzipExtensions = ['html', 'js', 'css']
config.plugins.push(
new CompressionWebpackPlugin({
filename: '[path].gz[query]',
algorithm: 'gzip',
test: new RegExp(
'\\.(' + productionGzipExtensions.join('|') + ')$'
),
threshold: 10240, // 只有大小大于该值的资源会被处理 10240
minRatio: 0.8, // 只有压缩率小于这个值的资源才会被处理
})
)
}
}
报错
build 的时候,报错 TypeError: Cannot read property “‘tapPromise'” of undefined
解决办法
删除 compression-webpack-plugin,重新安装 6.1.1 版本后,问题解决
warning
Conflict: Multiple assets emit different content to the same filename js/.gz
6.1.1版本以后 filename 的写法发生了改变
解决办法
修改如下:
filename: '[path][base].gz',
