import { existsSync, readFileSync } from "node:fs"; import react from "@vitejs/plugin-react"; import type { Plugin } from "vite"; import { defineConfig } from "vite"; export default defineConfig(({ command }) => ({ plugins: [react(), deploymentHtml(command === "build")], build: { chunkSizeWarningLimit: 700, rollupOptions: { output: { manualChunks: { charts: ["recharts"], motion: ["framer-motion"], icons: ["lucide-react"], }, }, }, }, })); function deploymentHtml(enabled: boolean): Plugin { return { name: "deployment-html", transformIndexHtml(html) { if (!enabled) return html; return html .replace("", `${readOptional(".deploy/head.html")}`) .replace("", `${readOptional(".deploy/body-end.html")}`); }, }; } function readOptional(path: string) { if (!existsSync(path)) return ""; return `\n${readFileSync(path, "utf8").trim()}\n`; }