From 2b3715f1610b4176d7abe33e34542389cef61853 Mon Sep 17 00:00:00 2001
From: zhuguifei <zhuguifei@zhuguifeideiMac.local>
Date: 星期六, 12 四月 2025 17:12:22 +0800
Subject: [PATCH] Merge branch 'main' of http://lanpucloud.cn:1111/r/eims-master

---
 eims-ui-mobile/vite.config.ts |  160 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 160 insertions(+), 0 deletions(-)

diff --git a/eims-ui-mobile/vite.config.ts b/eims-ui-mobile/vite.config.ts
new file mode 100644
index 0000000..f0fec23
--- /dev/null
+++ b/eims-ui-mobile/vite.config.ts
@@ -0,0 +1,160 @@
+import Uni from '@dcloudio/vite-plugin-uni'
+import dayjs from 'dayjs'
+import path from 'node:path'
+import { defineConfig, loadEnv } from 'vite'
+// @see https://uni-helper.js.org/vite-plugin-uni-pages
+import UniPages from '@uni-helper/vite-plugin-uni-pages'
+// @see https://uni-helper.js.org/vite-plugin-uni-layouts
+import UniLayouts from '@uni-helper/vite-plugin-uni-layouts'
+// @see https://github.com/uni-helper/vite-plugin-uni-platform
+// 闇�瑕佷笌 @uni-helper/vite-plugin-uni-pages 鎻掍欢涓�璧蜂娇鐢�
+import UniPlatform from '@uni-helper/vite-plugin-uni-platform'
+// @see https://github.com/uni-helper/vite-plugin-uni-manifest
+import UniManifest from '@uni-helper/vite-plugin-uni-manifest'
+// @see https://unocss.dev/
+import { visualizer } from 'rollup-plugin-visualizer'
+import UnoCSS from 'unocss/vite'
+import AutoImport from 'unplugin-auto-import/vite'
+import ViteRestart from 'vite-plugin-restart'
+import { copyNativeRes } from './vite-plugins/copyNativeRes'
+
+// https://vitejs.dev/config/
+export default ({ command, mode }) => {
+  // console.log(mode === process.env.NODE_ENV) // true
+
+  // mode: 鍖哄垎鐢熶骇鐜杩樻槸寮�鍙戠幆澧�
+  console.log('command, mode -> ', command, mode)
+  // pnpm dev:h5 鏃跺緱鍒� => serve development
+  // pnpm build:h5 鏃跺緱鍒� => build production
+  // pnpm dev:mp-weixin 鏃跺緱鍒� => build development (娉ㄦ剰鍖哄埆锛宑ommand涓篵uild)
+  // pnpm build:mp-weixin 鏃跺緱鍒� => build production
+  // pnpm dev:app 鏃跺緱鍒� => build development (娉ㄦ剰鍖哄埆锛宑ommand涓篵uild)
+  // pnpm build:app 鏃跺緱鍒� => build production
+  // dev 鍜� build 鍛戒护鍙互鍒嗗埆浣跨敤 .env.development 鍜� .env.production 鐨勭幆澧冨彉閲�
+
+  const { UNI_PLATFORM } = process.env
+  console.log('UNI_PLATFORM -> ', UNI_PLATFORM) // 寰楀埌 mp-weixin, h5, app 绛�
+
+  const env = loadEnv(mode, path.resolve(process.cwd(), 'env'))
+  const {
+    VITE_APP_PORT,
+    VITE_SERVER_BASEURL,
+    VITE_DELETE_CONSOLE,
+    VITE_SHOW_SOURCEMAP,
+    VITE_APP_PROXY,
+    VITE_APP_PROXY_PREFIX,
+  } = env
+  console.log('鐜鍙橀噺 env -> ', env)
+
+  return defineConfig({
+    envDir: './env', // 鑷畾涔塭nv鐩綍
+
+    plugins: [
+      UniPages({
+        exclude: ['**/components/**/**.*'],
+        routeBlockLang: 'json5', // 铏界劧璁句簡榛樿鍊硷紝浣嗘槸vue鏂囦欢杩樻槸瑕佸姞涓� lang="json5", 杩欐牱鎵嶈兘寰堝ソ鍦版牸寮忓寲
+        // homePage 閫氳繃 vue 鏂囦欢鐨� route-block 鐨則ype="home"鏉ヨ瀹�
+        // pages 鐩綍涓� src/pages锛屽垎鍖呯洰褰曚笉鑳介厤缃湪pages鐩綍涓�
+        // subPackages: ['src/pages-sub'], // 鏄釜鏁扮粍锛屽彲浠ラ厤缃涓紝浣嗘槸涓嶈兘涓簆ages閲岄潰鐨勭洰褰�
+        dts: 'src/types/uni-pages.d.ts',
+      }),
+      UniLayouts(),
+      UniPlatform(),
+      UniManifest(),
+      // UniXXX 闇�瑕佸湪 Uni 涔嬪墠寮曞叆
+      Uni(),
+      {
+        // 涓存椂瑙e喅 dcloudio 瀹樻柟鐨� @dcloudio/uni-mp-compiler 鍑虹幇鐨勭紪璇� BUG
+        // 鍙傝�� github issue: https://github.com/dcloudio/uni-app/issues/4952
+        // 鑷畾涔夋彃浠剁鐢� vite:vue 鎻掍欢鐨� devToolsEnabled锛屽己鍒剁紪璇� vue 妯℃澘鏃� inline 涓� true
+        name: 'fix-vite-plugin-vue',
+        configResolved(config) {
+          const plugin = config.plugins.find((p) => p.name === 'vite:vue')
+          if (plugin && plugin.api && plugin.api.options) {
+            plugin.api.options.devToolsEnabled = false
+          }
+        },
+      },
+      UnoCSS(),
+      AutoImport({
+        imports: ['vue', 'uni-app'],
+        dts: 'src/types/auto-import.d.ts',
+        dirs: ['src/hooks'], // 鑷姩瀵煎叆 hooks
+        eslintrc: { enabled: true },
+        vueTemplate: true, // default false
+      }),
+
+      ViteRestart({
+        // 閫氳繃杩欎釜鎻掍欢锛屽湪淇敼vite.config.js鏂囦欢鍒欎笉闇�瑕侀噸鏂拌繍琛屼篃鐢熸晥閰嶇疆
+        restart: ['vite.config.js'],
+      }),
+      // h5鐜澧炲姞 BUILD_TIME 鍜� BUILD_BRANCH
+      UNI_PLATFORM === 'h5' && {
+        name: 'html-transform',
+        transformIndexHtml(html) {
+          return html.replace('%BUILD_TIME%', dayjs().format('YYYY-MM-DD HH:mm:ss'))
+        },
+      },
+      // 鎵撳寘鍒嗘瀽鎻掍欢锛宧5 + 鐢熶骇鐜鎵嶅脊鍑�
+      UNI_PLATFORM === 'h5' &&
+        mode === 'production' &&
+        visualizer({
+          filename: './node_modules/.cache/visualizer/stats.html',
+          open: true,
+          gzipSize: true,
+          brotliSize: true,
+        }),
+      // 鍙湁鍦� app 骞冲彴鏃舵墠鍚敤 copyNativeRes 鎻掍欢
+      UNI_PLATFORM === 'app' && copyNativeRes(),
+    ],
+    define: {
+      __UNI_PLATFORM__: JSON.stringify(UNI_PLATFORM),
+      __VITE_APP_PROXY__: JSON.stringify(VITE_APP_PROXY),
+    },
+    css: {
+      postcss: {
+        plugins: [
+          // autoprefixer({
+          //   // 鎸囧畾鐩爣娴忚鍣�
+          //   overrideBrowserslist: ['> 1%', 'last 2 versions'],
+          // }),
+        ],
+      },
+    },
+
+    resolve: {
+      alias: {
+        '@': path.join(process.cwd(), './src'),
+        '@img': path.join(process.cwd(), './src/static/images'),
+      },
+    },
+    server: {
+      host: '0.0.0.0',
+      hmr: true,
+      port: Number.parseInt(VITE_APP_PORT, 10),
+      // 浠� H5 绔敓鏁堬紝鍏朵粬绔笉鐢熸晥锛堝叾浠栫璧癰uild锛屼笉璧癲evServer)
+      proxy: JSON.parse(VITE_APP_PROXY)
+        ? {
+            [VITE_APP_PROXY_PREFIX]: {
+              target: VITE_SERVER_BASEURL,
+              changeOrigin: true,
+              rewrite: (path) => path.replace(new RegExp(`^${VITE_APP_PROXY_PREFIX}`), ''),
+            },
+          }
+        : undefined,
+    },
+    build: {
+      // 鏂逛究闈瀐5绔皟璇�
+      sourcemap: VITE_SHOW_SOURCEMAP === 'true', // 榛樿鏄痜alse
+      target: 'es6',
+      // 寮�鍙戠幆澧冧笉鐢ㄥ帇缂�
+      minify: mode === 'development' ? false : 'terser',
+      terserOptions: {
+        compress: {
+          drop_console: VITE_DELETE_CONSOLE === 'true',
+          drop_debugger: true,
+        },
+      },
+    },
+  })
+}

--
Gitblit v1.9.3