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 }) => { // Variable fournie par start.sh, ou par un .env local au frontend. const env = loadEnv(mode, process.cwd(), "") const backendPort = process.env.BACKEND_PORT || env.BACKEND_PORT || "1029" const proxyTarget = `http://127.0.0.1:${backendPort}` const proxy = Object.fromEntries( ["/api", "/static"].map((path) => [ path, { target: proxyTarget, changeOrigin: true }, ]), ) return { plugins: [react(), tailwindcss()], resolve: { alias: { "@": fileURLToPath(new URL("./src", import.meta.url)) } }, server: { host: "0.0.0.0", proxy }, preview: { host: "0.0.0.0", proxy }, } })