import { fileURLToPath, URL } from "node:url"; import { defineConfig, loadEnv } from "vite"; import tailwindcss from "@tailwindcss/vite"; import vue from "@vitejs/plugin-vue"; import vueDevTools from "vite-plugin-vue-devtools"; // Dev-server proxy targets. Compose publishes none of these services, so the // defaults are each service's own port on the host; /py and /radio share // :8000, so at most one is right. Override with VITE_PROXY_API, _GITEA, _PY // and _RADIO (shell or vue/.env.local). API, GITEA and RADIO may point at a // running Caddy; PY may not (see the rewrite below). const DEFAULT_PROXY = { VITE_PROXY_API: "http://localhost:8080", VITE_PROXY_GITEA: "http://localhost:3000", VITE_PROXY_PY: "http://localhost:8000", VITE_PROXY_RADIO: "http://localhost:8000", }; // https://vite.dev/config/ export default defineConfig(({ mode }) => { // process.env wins over the .env files. const env = { ...DEFAULT_PROXY, ...loadEnv(mode, process.cwd(), "VITE_PROXY_"), }; for (const key of Object.keys(DEFAULT_PROXY)) if (process.env[key]) env[key] = process.env[key]; return { plugins: [ vue(), ...(process.env.NODE_ENV !== "production" ? [vueDevTools()] : []), tailwindcss(), ], resolve: { alias: { "@": fileURLToPath(new URL("./src", import.meta.url)), }, }, server: { host: "0.0.0.0", proxy: { "/api": env.VITE_PROXY_API, "/gitea": env.VITE_PROXY_GITEA, "/radio": env.VITE_PROXY_RADIO, // Caddy strips /py, so this must target uvicorn directly. "/py": { target: env.VITE_PROXY_PY, rewrite: (path) => path.replace(/^\/py/, ""), }, }, }, }; });