File
Blob: vite.config.ts
| 1 | import { relative } from "node:path"; |
| 2 | import { fileURLToPath, URL } from "node:url"; |
| 3 | import { cloudflare } from "@cloudflare/vite-plugin"; |
| 4 | import tailwindcss from "@tailwindcss/vite"; |
| 5 | import react from "@vitejs/plugin-react"; |
| 6 | import { defineConfig } from "vite"; |
| 7 | |
| 8 | const projectRoot = fileURLToPath(new URL(".", import.meta.url)); |
| 9 | |
| 10 | const shouldIgnoreWatchPath = (watchedPath: string) => { |
| 11 | const relativePath = relative(projectRoot, watchedPath).replaceAll("\\", "/"); |
| 12 | |
| 13 | if (relativePath === "" || relativePath === ".") { |
| 14 | return false; |
| 15 | } |
| 16 | |
| 17 | if (relativePath === "index.html") { |
| 18 | return false; |
| 19 | } |
| 20 | |
| 21 | if (relativePath === ".dev.vars") { |
| 22 | return false; |
| 23 | } |
| 24 | |
| 25 | return relativePath !== "src" && !relativePath.startsWith("src/"); |
| 26 | }; |
| 27 | |
| 28 | // E2E suite seeds an isolated D1/KV/R2 state directory per run; the |
| 29 | // FLAMEMAIL_E2E_PERSIST_PATH env points the cloudflare-vite plugin at |
| 30 | // that directory so vite/miniflare share the same state that |
| 31 | // `wrangler ... migrations apply --persist-to` wrote. Local dev leaves |
| 32 | // the env unset and uses the default `.wrangler/state` path. |
| 33 | const e2ePersistStatePath = process.env.FLAMEMAIL_E2E_PERSIST_PATH; |
| 34 | |
| 35 | export default defineConfig({ |
| 36 | plugins: [ |
| 37 | tailwindcss(), |
| 38 | react(), |
| 39 | cloudflare({ |
| 40 | ...(e2ePersistStatePath ? { persistState: { path: e2ePersistStatePath } } : {}), |
| 41 | }), |
| 42 | ], |
| 43 | resolve: { |
| 44 | alias: { |
| 45 | "@": fileURLToPath(new URL("./src", import.meta.url)), |
| 46 | }, |
| 47 | }, |
| 48 | build: { |
| 49 | outDir: "dist", |
| 50 | emptyOutDir: true, |
| 51 | }, |
| 52 | server: { |
| 53 | host: true, |
| 54 | watch: { |
| 55 | ignored: shouldIgnoreWatchPath, |
| 56 | }, |
| 57 | }, |
| 58 | }); |