library-picturebook-activity/frontend/vite.config.ts
2026-04-08 15:32:18 +08:00

53 lines
1.4 KiB
TypeScript

import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
// 根据环境设置 base 路径
const getBase = (mode: string) => {
switch (mode) {
case "test":
return "/web-test/";
case "production":
return "/web/";
default:
return "/";
}
};
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
// vite.config 顶层无法从 .env 读取 VITE_*,需在回调内 loadEnv
const env = loadEnv(mode, process.cwd(), "");
// AI 绘本子项目 Vite 开发服务地址(主站 /ai-web 代理到此地址,需与 lesingle-aicreate-client 端口一致)
const aiProxyTarget =
env.VITE_AI_CLIENT_DEV_URL ||
env.VITE_AI_POST_MESSAGE_URL ||
"http://localhost:3001";
return {
base: getBase(mode),
plugins: [vue()],
resolve: {
alias: {
"@": resolve(__dirname, "src"),
},
},
server: {
host: "0.0.0.0",
port: 3000,
proxy: {
"/api": {
target: "http://localhost:8580",
changeOrigin: true,
// rewrite: (path) => path.replace(/^\/api/, ''),
},
"/ai-web": {
target: aiProxyTarget,
changeOrigin: true,
// 子项目 base 为 /ai-web/,不重写路径,直接转发到子 dev server
},
},
},
};
});