【VUE】vue配置Gzip压缩
安装compression-webpack-pluginnpm install compression-webpack-plugin --save-devvue.config.js配置Gzip压缩// 导入compression-webpack-pluginconst CompressionWebpackPlugin = require('compression-webpack-plug...
·
安装compression-webpack-plugin
npm install compression-webpack-plugin --save-dev
vue.config.js配置Gzip压缩
// 导入compression-webpack-plugin
const CompressionWebpackPlugin = require('compression-webpack-plugin')
// 定义压缩文件类型
const productionGzipExtensions = ['js', 'css']
module.exports = {
// 配置反向代理
devServer: {
proxy: {
'/api': {
target: 'http://172.31.120.61:8088/',
ws: true,
changeOrigin: true,
pathRewrite: {
'^/api': ''
}
}
}
},
configureWebpack: {
plugins: [
new CompressionWebpackPlugin({
filename: '[path].gz[query]',
algorithm: 'gzip',
test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
threshold: 10240,
minRatio: 0.8
})
]
}
}
配置Nginx
gzip on; #开启或关闭gzip on off
gzip_disable "msie6"; #不使用gzip IE6
gzip_min_length 100k; #gzip压缩最小文件大小,超出进行压缩(自行调节)
gzip_buffers 4 16k; #buffer 不用修改
gzip_comp_level 8; #压缩级别:1-10,数字越大压缩的越好,时间也越长
gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; # 压缩文件类型
更多推荐
已为社区贡献15条内容
所有评论(0)