From c314661d7353b58f926aa5a99abfc40313638521 Mon Sep 17 00:00:00 2001
From: yxh <172933527@qq.com>
Date: 星期日, 27 九月 2026 16:28:36 +0800
Subject: [PATCH] 瘦身了框架
---
build/vite/index.ts | 14 ++++++++++++--
1 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/build/vite/index.ts b/build/vite/index.ts
index 585759f..60ba3ec 100644
--- a/build/vite/index.ts
+++ b/build/vite/index.ts
@@ -1,4 +1,5 @@
import { resolve } from 'path'
+import { loadEnv } from 'vite'
import Vue from '@vitejs/plugin-vue'
import VueJsx from '@vitejs/plugin-vue-jsx'
import progress from 'vite-plugin-progress'
@@ -16,8 +17,17 @@
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import UnoCSS from 'unocss/vite'
-export function createVitePlugins() {
+export function createVitePlugins(mode?: string) {
const root = process.cwd()
+
+ // 璇诲彇褰撳墠 mode 瀵瑰簲鐨� .env 閰嶇疆锛岀敤浜庢寜鐜寮�鍏虫彃浠�
+ const env = loadEnv(mode ?? 'production', root)
+
+ // 鏄惁浜у嚭 .gz 鍘嬬缉鏂囦欢銆�
+ // 榛樿 true锛屼繚鎸佷笌鏀归�犲墠涓�鑷达紙鍓嶇鐢� nginx 鎵樼鏃讹紝.gz 閰嶅悎 gzip_static 鏈夌敤锛夈��
+ // 鍚堝苟閮ㄧ讲锛堝墠绔墦杩� jar锛夋椂搴旇涓� false锛歋pring Boot 涓嶄細鑷姩鎻愪緵 .gz锛�
+ // 杩欎簺鏂囦欢鍙細鐧藉崰 jar 浣撶Н銆�
+ const enableCompression = env.VITE_COMPRESSION !== 'false'
// 璺緞鏌ユ壘
function pathResolve(dir: string) {
@@ -82,7 +92,7 @@
}),
viteCompression({
verbose: true, // 鏄惁鍦ㄦ帶鍒跺彴杈撳嚭鍘嬬缉缁撴灉
- disable: false, // 鏄惁绂佺敤
+ disable: !enableCompression, // 鏄惁绂佺敤锛堢敱 .env 鐨� VITE_COMPRESSION 鎺у埗锛�
threshold: 10240, // 浣撶Н澶т簬 threshold 鎵嶄細琚帇缂�,鍗曚綅 b
algorithm: 'gzip', // 鍘嬬缉绠楁硶,鍙�� [ 'gzip' , 'brotliCompress' ,'deflate' , 'deflateRaw']
ext: '.gz', // 鐢熸垚鐨勫帇缂╁寘鍚庣紑
--
Gitblit v1.9.3