import tailwindcss from "@tailwindcss/vite"; import react from "@vitejs/plugin-react"; import { execSync } from "node:child_process"; import { readFileSync } from "node:fs"; import { rm } from "node:fs/promises"; import { join } from "node:path"; import { defineConfig, type Plugin } from "vite"; /** * The user's source map art (public/assets/map) is large and only an input to * scripts/map-art.mjs; the app loads public/assets/map-gen. Drop the sources * from the build output (decision 0.5.37). */ function omitSourceArt(): Plugin { let outDir = "dist"; return { name: "omit-source-art", apply: "build", configResolved(config) { outDir = config.build.outDir; }, async closeBundle() { await rm(join(outDir, "assets/map"), { recursive: true, force: true }); }, }; } /** Version from package.json and the git commit, shown in Settings → About (CR-011). */ function buildInfo() { const { version } = JSON.parse( readFileSync(new URL("./package.json", import.meta.url), "utf8"), ) as { version: string; }; let build = "dev"; try { build = execSync("git rev-parse --short HEAD", { stdio: ["ignore", "pipe", "ignore"] }) .toString() .trim(); } catch { // Not a git checkout (e.g. a tarball build): keep "dev". } return { __APP_VERSION__: JSON.stringify(version), __APP_BUILD__: JSON.stringify(build) }; } export default defineConfig({ define: buildInfo(), plugins: [react(), tailwindcss(), omitSourceArt()], server: { // Same-domain API in development too (decision 0.5.20). The server listens on // IPv4 only, so target 127.0.0.1 rather than localhost. // API_PROXY_TARGET lets a second dev stack (e.g. screenshots) use another API port. proxy: { "/api": process.env.API_PROXY_TARGET ?? "http://127.0.0.1:3000" }, }, });