From 39630d39e556459eaba59d0228600f369bd75786 Mon Sep 17 00:00:00 2001 From: zlwu <704541015@qq.com> Date: Sun, 9 Aug 2026 16:01:40 +0800 Subject: [PATCH] fix(bx-mobile): load VITE_API_PROXY_URL via loadEnv in vite config Co-authored-by: Cursor --- bx-mobile/vite.config.ts | 43 +++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/bx-mobile/vite.config.ts b/bx-mobile/vite.config.ts index a77fdf17a..eb6f13184 100644 --- a/bx-mobile/vite.config.ts +++ b/bx-mobile/vite.config.ts @@ -1,28 +1,31 @@ -import { defineConfig } from 'vite' +import { defineConfig, loadEnv } from 'vite' import vue from '@vitejs/plugin-vue' import Components from 'unplugin-vue-components/vite' import { VantResolver } from '@vant/auto-import-resolver' import { fileURLToPath, URL } from 'node:url' -export default defineConfig({ - plugins: [ - vue(), - Components({ - resolvers: [VantResolver()], - }), - ], - resolve: { - alias: { - '@': fileURLToPath(new URL('./src', import.meta.url)), - }, - }, - server: { - port: 5174, - proxy: { - '/api': { - target: process.env.VITE_API_PROXY_URL || 'http://localhost:8000', - changeOrigin: true, +export default defineConfig(({ mode }) => { + const env = loadEnv(mode, process.cwd()) + return { + plugins: [ + vue(), + Components({ + resolvers: [VantResolver()], + }), + ], + resolve: { + alias: { + '@': fileURLToPath(new URL('./src', import.meta.url)), }, }, - }, + server: { + port: 5174, + proxy: { + '/api': { + target: env.VITE_API_PROXY_URL || 'http://localhost:8000', + changeOrigin: true, + }, + }, + }, + } })