| 1 | import { foldkit } from "@foldkit/vite-plugin"; |
| 2 | import { defineConfig } from "vite"; |
| 3 | |
| 4 | // The deployment this build belongs to. The server stamps it on the rendered |
| 5 | // root and the client carries the same value, so hydration can refuse a page |
| 6 | // from a different deployment before adopting its DOM. A hydratable render |
| 7 | // fails without one, so a build must always have it: CI supplies a real |
| 8 | // per-deployment value and a local build falls back to a fresh one rather |
| 9 | // than a constant, which would make a stale page look current. |
| 10 | const buildId = |
| 11 | process.env.FOLDKIT_BUILD_ID ?? `local-${Date.now().toString(36)}`; |
| 12 | |
| 13 | export default defineConfig({ |
| 14 | // Client and server must receive the same buildId from this config evaluation. |
| 15 | builder: { sharedConfigBuild: true }, |
| 16 | // NOTE: the plugin's `ssr: { serverEntry }` option is deliberately NOT set. |
| 17 | // It serves rendered pages from the Vite dev server by loading the entry |
| 18 | // through `ssrLoadModule`, which requires a runnable `ssr` environment — |
| 19 | // and under `alchemy dev` that environment belongs to workerd, which is not |
| 20 | // runnable. It is also redundant here: requests reach `src/worker.ts`, |
| 21 | // which renders through the same entry. |
| 22 | plugins: [foldkit({ buildId })], |
| 23 | optimizeDeps: { |
| 24 | entries: ["src/entry.ts"], |
| 25 | }, |
| 26 | }); |