Files
huachuang/nl-ui/nl-ui-admin-vben/yudao-ui-admin-vben/apps/web-antdv-next/vite.config.ts
2026-07-08 15:56:59 +08:00

35 lines
1.0 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 { loadEnv } from 'vite';
import { defineConfig } from '@vben/vite-config';
// @ts-ignore
export default defineConfig(async ({ mode }) => {
const env = loadEnv(mode, process.cwd(), 'VITE_');
const baseUrl = env.VITE_BASE_URL || 'http://localhost:48080';
const apiUrl = env.VITE_GLOB_API_URL || '/admin-api';
// 如果 apiUrl 已经是完整 URL如生产环境不需要 proxy
// 开发环境 apiUrl 为相对路径(如 /admin-api通过 proxy 转发
const isFullUrl = /^https?:\/\//.test(apiUrl);
return {
application: {},
vite: {
server: {
allowedHosts: true,
proxy: isFullUrl
? {}
: {
[apiUrl]: {
changeOrigin: true,
rewrite: (path) => path.replace(new RegExp(`^${apiUrl}`), ''),
// 代理目标地址,从环境变量 VITE_BASE_URL + VITE_GLOB_API_URL 拼接
target: `${baseUrl}${apiUrl}`,
ws: true,
},
},
},
},
};
});