From 91e04a8d1824bf7fd01f7879310e6ff1470e36f0 Mon Sep 17 00:00:00 2001 From: Orange Date: Wed, 24 Mar 2021 18:32:54 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nginx.conf | 10 ++++++++++ package.json | 1 + vue.config.js | 13 ++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/nginx.conf b/nginx.conf index 7e98037ce..f5164215f 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,6 +1,16 @@ server { listen 80; + gzip on; + gzip_min_length 1k; + gzip_buffers 4 16k; + #gzip_http_version 1.0; + gzip_comp_level 8; + gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; + gzip_vary off; + gzip_static on; + gzip_disable "MSIE [1-6]."; + location /ui/ { try_files $uri / /ui/index.html; alias /opt/lina/; diff --git a/package.json b/package.json index bd9f4695f..28956643b 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,7 @@ "babel-eslint": "10.0.1", "babel-jest": "23.6.0", "chalk": "2.4.2", + "compression-webpack-plugin": "^6.1.1", "connect": "3.6.6", "element-theme-chalk": "^2.13.1", "eslint": "^5.15.3", diff --git a/vue.config.js b/vue.config.js index 24c4319e7..419491b5c 100644 --- a/vue.config.js +++ b/vue.config.js @@ -1,6 +1,9 @@ 'use strict' const path = require('path') const defaultSettings = require('./src/settings.js') +const CompressionWebpackPlugin = require('compression-webpack-plugin') +const productionGzipExtensions = /\.(js|css|json|txt|ico|svg)(\?.*)?$/i + function resolve(dir) { return path.join(__dirname, dir) @@ -82,7 +85,15 @@ module.exports = { alias: { '@': resolve('src') } - } + }, + plugins: [ + new CompressionWebpackPlugin({ + algorithm: 'gzip', + test: productionGzipExtensions, // 处理所有匹配此 {RegExp} 的资源 + threshold: 10240, // 只处理比这个值大的资源。按字节计算(楼主设置10K以上进行压缩) + minRatio: 0.8 // 只有压缩率比这个值小的资源才会被处理 + }) + ] }, chainWebpack(config) { // it can improve the speed of the first screen, it is recommended to turn on preload