From 260b7f851e6c59c8f4ba3d1b369306a4b34a5b9f Mon Sep 17 00:00:00 2001 From: let5sne Date: Mon, 20 Jul 2026 09:18:39 +0800 Subject: [PATCH] chore(mobile): reuse dev-api proxy config for vite preview --- mobile-uni/vite.config.ts | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/mobile-uni/vite.config.ts b/mobile-uni/vite.config.ts index 395f67ff..864940bb 100644 --- a/mobile-uni/vite.config.ts +++ b/mobile-uni/vite.config.ts @@ -8,19 +8,27 @@ const proxyTarget = process.env.VITE_PROXY_TARGET || 'https://wygj-api.localhost // 代理到线上等已带 /dev-api 前缀的网关时,设 VITE_PROXY_KEEP_PREFIX=1 保留前缀 const keepProxyPrefix = process.env.VITE_PROXY_KEEP_PREFIX === '1'; +const proxy = { + '/dev-api': { + target: proxyTarget, + changeOrigin: true, + secure: false, + rewrite: (path) => (keepProxyPrefix ? path : path.replace(/^\/dev-api/, '')) + } +}; + export default defineConfig({ plugins: [uni()], server: { host: devHost, port: devPort, strictPort: true, - proxy: { - '/dev-api': { - target: proxyTarget, - changeOrigin: true, - secure: false, - rewrite: (path) => (keepProxyPrefix ? path : path.replace(/^\/dev-api/, '')) - } - } + proxy + }, + preview: { + host: devHost, + port: devPort, + strictPort: true, + proxy } });