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",