使用环境:vue版本2.6.11,vue-cli3
1. 安装compression-webpack-plugin
npm install compression-webpack-plugin@6.0.0 -D
2. vue.config.js中导入使用
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const productionGzipExtensions = ['js', 'css']
module.exports = {
configureWebpack: {
plugins: [
new CompressionWebpackPlugin({
filename: '[path][base].gz',
algorithm: 'gzip',
test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
threshold: 10240,
minRatio: 0.8
}),
]
}
}