- 后端多环境配置(dev, prod) - Docker 部署支持(Dockerfile, docker-compose.yml) - Java 部署脚本(deploy.sh) - 前端构建脚本(build.sh,支持自定义后端地址) - 健康检查接口(/api/health) - 完整的部署文档(docs/DEPLOYMENT.md) - 前端环境变量支持(VITE_API_URL, VITE_WS_URL)
38 lines
969 B
TypeScript
38 lines
969 B
TypeScript
import { defineConfig, loadEnv } from 'vite'
|
|
import react from '@vitejs/plugin-react'
|
|
|
|
// https://vitejs.dev/config/
|
|
export default defineConfig(({ mode }) => {
|
|
// 加载环境变量
|
|
const env = loadEnv(mode, process.cwd(), '')
|
|
|
|
// 从环境变量获取 API 地址,默认使用 localhost:8000
|
|
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,
|
|
changeOrigin: true,
|
|
rewrite: (path) => path.replace(/^\/api/, '/api')
|
|
},
|
|
'/ws': {
|
|
target: WS_URL,
|
|
ws: true,
|
|
changeOrigin: true
|
|
}
|
|
}
|
|
},
|
|
// 定义环境变量,在构建时注入
|
|
define: {
|
|
'import.meta.env.VITE_API_URL': JSON.stringify(API_URL),
|
|
'import.meta.env.VITE_WS_URL': JSON.stringify(WS_URL)
|
|
}
|
|
}
|
|
})
|
|
|