import { defineConfig } from "vite"; import react from "@vitejs/plugin-react"; import tailwindcss from "@tailwindcss/vite"; import { viteModuleInventoryPlugin } from "./scripts/lib/vite-module-inventory.ts"; /** * ยง6.1. One sub-path, declared once. * * `VITE_ROUTER_BASE_PATH` already drives the router and the Service Worker * scope. Vite's asset `base` was left at its default, so a build served from * `/app/` emitted root-absolute asset URLs and loaded nothing: the three * consumers of the same setting disagreed. They are read from one value here so * a sub-path deployment is coherent or fails at build time. */ function routerBasePath(environment: NodeJS.ProcessEnv): string { const declared = environment["VITE_ROUTER_BASE_PATH"]; if (declared === undefined || declared === "") return "/"; if (!declared.startsWith("/") || !declared.endsWith("/")) { throw new Error( `VITE_ROUTER_BASE_PATH must start and end with "/"; received ${declared}`, ); } return declared; } export default defineConfig({ base: routerBasePath(process.env), plugins: [react(), tailwindcss(), viteModuleInventoryPlugin()], build: { manifest: true, sourcemap: false, }, });