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) } +} })