import { fileURLToPath } from "node:url"; import tailwindcss from "@tailwindcss/vite"; import react from "@vitejs/plugin-react"; import { defineConfig, loadEnv } from "vite"; // 本项目固定端口:前端 7380,后端 7381(见 AGENTS.md「端口约定」) const WEB_PORT = 7380; const API_PORT = 7381; export default defineConfig(({ mode }) => { const env = loadEnv(mode, process.cwd(), ""); const proxyTarget = env.VITE_API_PROXY_TARGET || `http://127.0.0.1:${API_PORT}`; return { plugins: [react(), tailwindcss()], resolve: { alias: { "@": fileURLToPath(new URL("./src", import.meta.url)), }, }, server: { host: "0.0.0.0", port: WEB_PORT, strictPort: true, proxy: { "/api": { target: proxyTarget, changeOrigin: true, }, }, }, build: { outDir: "dist", sourcemap: false, }, }; });