From 1cbedb3420ae6cb2d87a9c2123a805f8e2b08948 Mon Sep 17 00:00:00 2001 From: jingrow Date: Mon, 3 Nov 2025 23:36:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96vite=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/jingrow/frontend/.env.development | 5 ----- apps/jingrow/frontend/vite.config.ts | 16 +++++++++++----- 2 files changed, 11 insertions(+), 10 deletions(-) delete mode 100644 apps/jingrow/frontend/.env.development diff --git a/apps/jingrow/frontend/.env.development b/apps/jingrow/frontend/.env.development deleted file mode 100644 index 30c0161..0000000 --- a/apps/jingrow/frontend/.env.development +++ /dev/null @@ -1,5 +0,0 @@ -## 前端环境变量 (Vite会读取VITE_前缀的变量) -# 开发环境:前端使用相对路径,通过Vite代理转发 -# 生产环境:前端直接请求后端服务器 -VITE_JINGROW_SERVER_URL= -VITE_BACKEND_SERVER_URL= diff --git a/apps/jingrow/frontend/vite.config.ts b/apps/jingrow/frontend/vite.config.ts index eb2e699..47a8aa0 100644 --- a/apps/jingrow/frontend/vite.config.ts +++ b/apps/jingrow/frontend/vite.config.ts @@ -1,4 +1,4 @@ -import { defineConfig } from 'vite' +import { defineConfig, loadEnv } from 'vite' import vue from '@vitejs/plugin-vue' import { resolve } from 'path' import { fileURLToPath, URL } from 'node:url' @@ -27,7 +27,12 @@ const currentDir = fileURLToPath(new URL('.', import.meta.url)) const appsDir = path.resolve(currentDir, '..', '..') const APPS_ORDER = loadAppsOrder(appsDir) -export default defineConfig({ +export default defineConfig(({ mode }) => { + const env = loadEnv(mode, process.cwd(), '') + const JINGROW_SERVER_URL = env.VITE_JINGROW_SERVER_URL + const BACKEND_URL = env.VITE_BACKEND_SERVER_URL + + return { plugins: [ vue(), Icons({ @@ -62,17 +67,17 @@ export default defineConfig({ }, proxy: { '/api/action': { - target: process.env.VITE_JINGROW_SERVER_URL || 'https://simon.c1.site.jingrow.com', + target: JINGROW_SERVER_URL, changeOrigin: true, secure: false }, '/api/data': { - target: process.env.VITE_BACKEND_SERVER_URL || 'http://localhost:9001', + target: BACKEND_URL, changeOrigin: true, secure: false }, '/jingrow': { - target: process.env.VITE_BACKEND_SERVER_URL || 'http://localhost:9001', + target: BACKEND_URL, changeOrigin: true, secure: false } @@ -88,4 +93,5 @@ export default defineConfig({ // 注入 apps.txt 的应用顺序到前端 __APPS_ORDER__: JSON.stringify(APPS_ORDER) } +} })