2025-12-03 02:48:02 +08:00
|
|
|
import { defineConfig, loadEnv } from 'vite'
|
2025-11-21 04:32:08 +08:00
|
|
|
import react from '@vitejs/plugin-react'
|
|
|
|
|
|
|
|
|
|
// https://vitejs.dev/config/
|
2025-12-03 02:48:02 +08:00
|
|
|
export default defineConfig(({ mode }) => {
|
|
|
|
|
// 加载环境变量
|
|
|
|
|
const env = loadEnv(mode, process.cwd(), '')
|
|
|
|
|
|
2025-12-03 03:08:53 +08:00
|
|
|
// 从环境变量获取后端地址,用于开发环境代理
|
|
|
|
|
// 如果未设置,使用默认值 localhost:8000
|
2025-12-03 02:48:02 +08:00
|
|
|
const API_URL = env.VITE_API_URL || 'http://localhost:8000'
|
|
|
|
|
const WS_URL = env.VITE_WS_URL || 'ws://localhost:8000'
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
plugins: [react()],
|
|
|
|
|
server: {
|
|
|
|
|
port: 3000,
|
|
|
|
|
proxy: {
|
|
|
|
|
'/api': {
|
|
|
|
|
target: API_URL,
|
2025-12-03 03:08:53 +08:00
|
|
|
changeOrigin: true
|
2025-12-03 02:48:02 +08:00
|
|
|
},
|
|
|
|
|
'/ws': {
|
|
|
|
|
target: WS_URL,
|
|
|
|
|
ws: true,
|
|
|
|
|
changeOrigin: true
|
|
|
|
|
}
|
2025-11-21 04:32:08 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|