Procházet zdrojové kódy

新增 .env.production.VITE_COMPRESSION压缩配置
优化 打包文件大小超过5kb才压缩

zhontai před 2 roky
rodič
revize
441f90b73d
6 změnil soubory, kde provedl 18 přidání a 12 odebrání
  1. 3 0
      .env.production
  2. 0 0
      gen/gen-api.js
  3. 6 6
      package-lock.json
  4. 5 5
      package.json
  5. 2 1
      src/utils/vite.ts
  6. 2 0
      vite.config.ts

+ 3 - 0
.env.production

@@ -1,6 +1,9 @@
 # 线上环境
 ENV = 'production'
 
+# 开启压缩
+VITE_COMPRESSION = true
+
 # public path 配置线上环境路径(打包)
 VITE_PUBLIC_PATH = '/'
 

+ 0 - 0
gen/gen-admin-api.js → gen/gen-api.js


+ 6 - 6
package-lock.json

@@ -1,12 +1,12 @@
 {
   "name": "admin.ui.plus",
-  "version": "1.2.0",
+  "version": "2.0.0",
   "lockfileVersion": 3,
   "requires": true,
   "packages": {
     "": {
       "name": "admin.ui.plus",
-      "version": "1.2.0",
+      "version": "2.0.0",
       "license": "MIT",
       "dependencies": {
         "@element-plus/icons-vue": "^2.1.0",
@@ -18,7 +18,7 @@
         "echarts": "^5.4.1",
         "echarts-gl": "^2.0.9",
         "echarts-wordcloud": "^2.1.0",
-        "element-plus": "^2.2.33",
+        "element-plus": "^2.2.35",
         "js-cookie": "^3.0.1",
         "js-table2excel": "^1.0.3",
         "jsplumb": "^2.15.6",
@@ -1985,9 +1985,9 @@
       }
     },
     "node_modules/element-plus": {
-      "version": "2.2.33",
-      "resolved": "https://registry.npmmirror.com/element-plus/-/element-plus-2.2.33.tgz",
-      "integrity": "sha512-E/PmMnv4+4I9Ue0ZDfx2gGgGj4iBlTCWcES3o4jxfYjayFlcQO3UvElJzhaJZ8vDm9yfNN7t2w/xYOhsSYCNNg==",
+      "version": "2.2.35",
+      "resolved": "https://registry.npmmirror.com/element-plus/-/element-plus-2.2.35.tgz",
+      "integrity": "sha512-if5QW41hQwVltekRS+avXYtqjRNra/fSgGstXKPR1lSJ81PWQccy+oztw/OP+USqZP/OejFs7rjLPk5MHgT40w==",
       "dependencies": {
         "@ctrl/tinycolor": "^3.4.1",
         "@element-plus/icons-vue": "^2.0.6",

+ 5 - 5
package.json

@@ -10,7 +10,7 @@
     "lint-fix": "eslint --fix --ext .js --ext .jsx --ext .vue src/",
     "format": "npx prettier --write .",
     "install:pkg": "npm install --registry https://registry.npmmirror.com",
-    "gen:admin-api": "node ./gen/gen-admin-api"
+    "gen:admin-api": "node ./gen/gen-api"
   },
   "dependencies": {
     "@element-plus/icons-vue": "^2.1.0",
@@ -22,7 +22,7 @@
     "echarts": "^5.4.1",
     "echarts-gl": "^2.0.9",
     "echarts-wordcloud": "^2.1.0",
-    "element-plus": "^2.2.33",
+    "element-plus": "^2.2.35",
     "js-cookie": "^3.0.1",
     "js-table2excel": "^1.0.3",
     "jsplumb": "^2.15.6",
@@ -49,17 +49,17 @@
     "@typescript-eslint/parser": "^5.54.0",
     "@vitejs/plugin-vue": "^4.0.0",
     "@vue/compiler-sfc": "^3.2.47",
+    "dotenv": "16.0.3",
     "eslint": "^8.35.0",
     "eslint-plugin-vue": "^9.9.0",
     "prettier": "^2.8.4",
     "sass": "^1.58.3",
+    "swagger-typescript-api": "12.0.3",
     "typescript": "^4.9.5",
     "vite": "^4.1.4",
     "vite-plugin-vue-setup-extend-plus": "^0.1.0",
     "vue-eslint-parser": "^9.1.0",
-    "dotenv": "16.0.3",
-    "vite-plugin-compression": "0.5.1",
-    "swagger-typescript-api": "12.0.3"
+    "vite-plugin-compression": "0.5.1"
   },
   "browserslist": [
     "> 1%",

+ 2 - 1
src/utils/vite.ts

@@ -4,6 +4,7 @@ import dotenv from 'dotenv'
 export interface ViteEnv {
   VITE_PORT: number
   VITE_OPEN: boolean
+  VITE_COMPRESSION: boolean
   VITE_PUBLIC_PATH: string
   VITE_API_URL: string
 }
@@ -31,7 +32,7 @@ export function loadEnv(mode: string): ViteEnv {
     let realName = (process.env as any)[envName].replace(/\\n/g, '\n')
     realName = realName === 'true' ? true : realName === 'false' ? false : realName
     if (envName === 'VITE_PORT') realName = Number(realName)
-    if (envName === 'VITE_OPEN') realName = Boolean(realName)
+    if (envName === 'VITE_OPEN' || envName === 'VITE_COMPRESSION') realName = Boolean(realName)
     if (envName === 'VITE_PROXY') {
       try {
         realName = JSON.parse(realName)

+ 2 - 0
vite.config.ts

@@ -21,6 +21,8 @@ const viteConfig = defineConfig(({ mode, command }: ConfigEnv) => {
       vue(),
       vueSetupExtend(),
       compression({
+        threshold: 5121,
+        disable: !env.VITE_COMPRESSION,
         deleteOriginFile: false,
       }),
     ],