Files
prop-ai-hr/mobile-uni/vite.config.ts
T
admin 5184672b61 fix(mobile): default h5 dev proxy to local backend on 8080
Bare npm run dev (including hosted preview sessions) has no portless
route, so the previous default target https://wygj-api.localhost was
unreachable and every API call failed with HTTP 500. scripts/dev.sh now
passes VITE_PROXY_TARGET explicitly, keeping the portless flow intact.
2026-07-20 13:55:50 +08:00

37 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { defineConfig } from 'vite';
import uniPlugin from '@dcloudio/vite-plugin-uni';
const uni = typeof uniPlugin === 'function' ? uniPlugin : uniPlugin.default;
const devPort = Number(process.env.PORT) || 5175;
const devHost = process.env.HOST || '0.0.0.0';
// 裸跑 npm run dev(如 Kimi Work 预览)时代理到本地 8080 后端;
// 走 portless(scripts/dev.sh)时由 VITE_PROXY_TARGET 显式指向 https://wygj-api.localhost
const proxyTarget = process.env.VITE_PROXY_TARGET || 'http://127.0.0.1:8080';
// 代理到线上等已带 /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
},
preview: {
host: devHost,
port: devPort,
strictPort: true,
proxy
}
});