2026-07-06 10:38:31 +08:00

70 lines
1.8 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 process from 'node:process';
import { defineConfig } from '@vben/vite-config';
const DEFAULT_DEV_SERVER_PORT = '5999';
const DEFAULT_DEV_API_TARGET = 'http://localhost:5667';
function resolveCliPort(argv = process.argv) {
for (let index = 0; index < argv.length; index += 1) {
const arg = argv[index];
if (arg === '--port') {
return argv[index + 1];
}
if (arg?.startsWith('--port=')) {
return arg.slice('--port='.length);
}
}
return undefined;
}
function resolveDevServerCacheDir(
port = resolveCliPort() || process.env.VITE_PORT || DEFAULT_DEV_SERVER_PORT,
) {
const normalizedPort = /^\d+$/.test(port ?? '')
? port
: DEFAULT_DEV_SERVER_PORT;
return `node_modules/.vite/web-antdv-next-${normalizedPort}`;
}
function resolveDevApiTarget(env = process.env) {
return env.VITE_DEV_API_TARGET || DEFAULT_DEV_API_TARGET;
}
export default defineConfig(async () => {
const devApiTarget = resolveDevApiTarget();
return {
application: {},
vite: {
cacheDir: resolveDevServerCacheDir(),
optimizeDeps: {
include: ['ant-design-x-vue'],
},
server: {
// Chromium 会阻止 6000 等不安全端口。5999 被占用时直接失败,避免 Vite 自动递增到不可访问端口。
strictPort: true,
proxy: {
'/api': {
changeOrigin: true,
// 代理到 .NET 后端 BuildFlow.Host
target: devApiTarget,
ws: true,
},
// SignalR Hub(聊天实时通信):与 /api 同后端,WebSocket 升级需 ws:true
'/hubs': {
changeOrigin: true,
target: devApiTarget,
ws: true,
},
},
},
},
};
});
export { resolveDevApiTarget, resolveDevServerCacheDir };