From 1cec38243c8db822b152910f581177fb665b9058 Mon Sep 17 00:00:00 2001 From: whyour Date: Mon, 29 Mar 2021 10:08:19 +0800 Subject: [PATCH] =?UTF-8?q?nginx=E5=A2=9E=E5=8A=A0gzip=E5=8E=8B=E7=BC=A9?= =?UTF-8?q?=EF=BC=8Cwebpack=E9=A2=84=E5=8E=8B=E7=BC=A9gz=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .umirc.ts | 12 ++++++++++++ docker/front.conf | 9 +++++++++ package.json | 1 + 3 files changed, 22 insertions(+) diff --git a/.umirc.ts b/.umirc.ts index 25de2061..1f033f8c 100644 --- a/.umirc.ts +++ b/.umirc.ts @@ -1,4 +1,5 @@ import { defineConfig } from 'umi'; +const CompressionPlugin = require('compression-webpack-plugin'); export default defineConfig({ hash: true, @@ -14,4 +15,15 @@ export default defineConfig({ changeOrigin: true, }, }, + chainWebpack(memo) { + memo.plugin('CompressionPlugin').use( + new CompressionPlugin({ + filename: '[path][base].gz', + algorithm: 'gzip', + test: /\.js$|\.css$|\.html$/, + threshold: 10240, + minRatio: 0.8, + }), + ); + }, }); diff --git a/docker/front.conf b/docker/front.conf index 49b34c4f..778e0a7a 100644 --- a/docker/front.conf +++ b/docker/front.conf @@ -11,6 +11,15 @@ server { proxy_pass http://api; } + gzip on; + gzip_static on; + gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; + gzip_proxied any; + gzip_vary on; + gzip_comp_level 6; + gzip_buffers 16 8k; + gzip_http_version 1.1; + location / { index index.html index.htm; try_files $uri $uri/ /index.html; diff --git a/package.json b/package.json index 70fb8c36..00de3f97 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "@types/react": "^17.0.0", "@types/react-dom": "^17.0.0", "@umijs/test": "^3.3.9", + "compression-webpack-plugin": "6.1.1", "lint-staged": "^10.0.7", "nodemon": "^2.0.4", "prettier": "^2.2.0",