Browse Source

```
feat(build): 增加构建配置优化和兼容性支持

- 添加 cross-env 依赖以支持环境变量配置
- 配置 NODE_OPTIONS=--max-old-space-size=8192 解决构建内存限制问题
- 添加 @vitejs/plugin-legacy 支持旧版浏览器兼容性
- 引入 terser 进行代码压缩优化
- 在 index.html 中添加 X-UA-Compatible 兼容性声明
```

gitboyzcf 2 weeks ago
parent
commit
193ff14a34
5 changed files with 675 additions and 121 deletions
  1. 1 0
      index.html
  2. 4 1
      package.json
  3. 657 117
      pnpm-lock.yaml
  4. 1 1
      src/api/modules/mr.js
  5. 12 2
      vite.config.js

+ 1 - 0
index.html

@@ -5,6 +5,7 @@
   <meta charset="UTF-8" />
   <link rel="icon" type="image/svg+xml" href="/vite.svg" />
   <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+  <meta http-equiv="X-UA-Compatible" content="ie=edge">
   <title>
     智能安全管控平台
   </title>

+ 4 - 1
package.json

@@ -5,7 +5,7 @@
   "type": "module",
   "scripts": {
     "dev": "vite --host",
-    "build": "vite build",
+    "build": "cross-env NODE_OPTIONS=--max-old-space-size=8192 vite build",
     "preview": "vite preview",
     "lint": "oxlint && eslint",
     "lint:fix": "oxlint --fix && eslint --fix",
@@ -68,11 +68,13 @@
     "@unocss/postcss": "^66.5.6",
     "@unocss/preset-legacy-compat": "^66.5.6",
     "@vitejs/plugin-basic-ssl": "^1.1.0",
+    "@vitejs/plugin-legacy": "^7.2.1",
     "@vitejs/plugin-vue": "^5.1.4",
     "@vitejs/plugin-vue-jsx": "^4.0.1",
     "browserslist": "^4.28.0",
     "commitlint": "^19.5.0",
     "consola": "^3.2.3",
+    "cross-env": "^10.1.0",
     "eslint": "^9.14.0",
     "eslint-plugin-json-es": "^1.6.0",
     "eslint-plugin-oxlint": "^0.11.0",
@@ -88,6 +90,7 @@
     "prettier": "^3.3.3",
     "rollup-plugin-delete": "^2.1.0",
     "sass": "1.32.13",
+    "terser": "^5.44.1",
     "unocss": "^0.64.0",
     "unocss-preset-autoprefixer": "^0.0.9",
     "unplugin-auto-import": "^0.18.3",

File diff suppressed because it is too large
+ 657 - 117
pnpm-lock.yaml


+ 1 - 1
src/api/modules/mr.js

@@ -284,7 +284,7 @@ export default {
       data
     })
   },
-  // 获取所有球机
+  // 获取所有信息
   API_INFO_BC_GET(params = {}) {
     return request({
       url: `/api/BallCamera/Info`,

+ 12 - 2
vite.config.js

@@ -2,6 +2,7 @@ import path from 'path'
 import { defineConfig } from 'vite'
 import vue from '@vitejs/plugin-vue'
 import vueJsx from '@vitejs/plugin-vue-jsx'
+// import legacy from '@vitejs/plugin-legacy'
 import AutoImport from 'unplugin-auto-import/vite'
 import Components from 'unplugin-vue-components/vite'
 import Icons from 'unplugin-icons/vite'
@@ -18,8 +19,8 @@ export default ({ mode, command }) => {
     build: {
       outDir: 'foreground',
       sourcemap: false,
-      minify: true,
       emptyOutDir: true,
+      chunkSizeWarningLimit: 1024,
       rollupOptions: {
         output: {
           chunkFileNames: 'js/[hash].js',
@@ -32,10 +33,19 @@ export default ({ mode, command }) => {
             }
           }
         }
-      }
+      },
+      minify: 'terser' // 必须使用 terser 才能支持 legacy 插件的混淆
     },
     plugins: [
       vue(),
+      // legacy({
+      //   targets: ['> 0.2%', 'not dead'],
+      //   polyfills: ['es.promise.finally', 'es/map', 'es/set'],
+      //   // 自动引入必要的 polyfill
+      //   additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
+      //   // 如果使用了特殊的 ES 语法,可以在这里强制 polyfill
+      //   modernPolyfills: true
+      // }),
       vueJsx(),
       // basicSsl(),
       Unocss({}),

Some files were not shown because too many files changed in this diff