Files
udmin/frontend/vite.config.ts
ayou 7c7adfe71a build(frontend): 添加不同环境的环境变量配置文件
添加开发、预发和生产环境的环境变量配置文件,包含端口、代理路径和API基地址等配置项
2025-08-28 20:59:00 +08:00

26 lines
758 B
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, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
// 单一配置文件 + 多环境 .env
// - .env.development / .env.production / .env.staging 中配置变量
// - 通过 loadEnv 读取并应用到开发服务器与代理
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, '.', '')
const port = Number(env.VITE_PORT || 5173)
const open = String(env.VITE_OPEN ?? 'true').toLowerCase() === 'true' || env.VITE_OPEN === '1'
const proxyTarget = env.VITE_ADMIN_PROXY_PATH || 'http://127.0.0.1:8080'
return {
plugins: [react()],
server: {
port,
open,
proxy: {
'/api': {
target: proxyTarget,
changeOrigin: true
}
}
}
}
})