2026-08-24 13:07:09 +08:00
|
|
|
import { defineConfig, loadEnv } from "vite";
|
|
|
|
|
import react from "@vitejs/plugin-react";
|
|
|
|
|
import tailwindcss from "@tailwindcss/vite";
|
|
|
|
|
import { fileURLToPath, URL } from "node:url";
|
|
|
|
|
|
|
|
|
|
export default defineConfig(({ mode }) => {
|
|
|
|
|
const rootDir = fileURLToPath(new URL(".", import.meta.url));
|
|
|
|
|
const env = loadEnv(mode, rootDir, "");
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
plugins: [react(), tailwindcss()],
|
|
|
|
|
resolve: {
|
|
|
|
|
alias: {
|
|
|
|
|
"@": fileURLToPath(new URL("./src", import.meta.url)),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
base: env.VITE_BASE_PATH || "/",
|
|
|
|
|
server: {
|
|
|
|
|
port: 5175,
|
|
|
|
|
proxy: {
|
|
|
|
|
// 开发期把 /api 与 /auth、/admin 代理到 server-core,避免跨域
|
|
|
|
|
"/api": { target: env.VITE_API_PROXY || "http://127.0.0.1:8090", changeOrigin: true },
|
|
|
|
|
"/auth": { target: env.VITE_API_PROXY || "http://127.0.0.1:8090", changeOrigin: true },
|
|
|
|
|
"/admin": { target: env.VITE_API_PROXY || "http://127.0.0.1:8090", changeOrigin: true },
|
2026-08-24 17:38:25 +08:00
|
|
|
// 仅代理 /park/api(园区 API),不要把 SPA 路由 /park 代理到后端,否则刷新返回 404
|
|
|
|
|
"/park/api": { target: env.VITE_API_PROXY || "http://127.0.0.1:8090", changeOrigin: true },
|
2026-08-24 13:07:09 +08:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
});
|