import { defineConfig, defaultClientConditions } from "vite"; import react from "@vitejs/plugin-react-swc"; import path from "path"; import { componentTagger } from "lovable-tagger"; // https://vitejs.dev/config/ const sidecarTarget = process.env.SIDECAR_TARGET ?? "http://127.0.0.1:3333"; export default defineConfig(({ mode }) => ({ server: { host: "::", port: 8080, hmr: { overlay: false, }, proxy: { "/api": { target: sidecarTarget, changeOrigin: true, }, "/health": { target: sidecarTarget, changeOrigin: true, }, "/ws": { target: sidecarTarget.replace(/^http/, "ws"), ws: true, }, }, }, plugins: [react(), mode === "development" && componentTagger()].filter(Boolean), build: { // Fonts stay separate files: the sidecar and Tauri CSPs allow fonts from // 'self' only, so a small subset inlined as a data: URL would be blocked. assetsInlineLimit: (filePath: string) => (/\.(?:woff2?|ttf|otf)$/.test(filePath) ? false : undefined), rollupOptions: { output: { // Split the heaviest independent vendor libraries out of the single // ~1.9MB app chunk so they cache separately and don't gate first paint. // The React runtime + router stay in ONE chunk so context/singleton // init order can't break across a chunk boundary. manualChunks(id: string) { if (!id.includes("node_modules")) return; if (id.includes("framer-motion")) return "vendor-motion"; if (id.includes("recharts") || id.includes("d3-") || id.includes("victory-")) return "vendor-charts"; if (id.includes("@radix-ui")) return "vendor-radix"; if (/[\\/]node_modules[\\/](react|react-dom|react-router|react-router-dom|scheduler)[\\/]/.test(id)) return "vendor-react"; }, }, }, }, resolve: { // Workspace packages (@waggle/shared) resolve to src/ through their // `source` export, so the UI builds without build:packages (P2.1). conditions: ["source", ...defaultClientConditions], alias: { "@": path.resolve(__dirname, "./src"), }, dedupe: ["react", "react-dom", "react/jsx-runtime", "react/jsx-dev-runtime"], }, }));