| 1 | import react from "@vitejs/plugin-react"; |
| 2 | import rsc from "@vitejs/plugin-rsc"; |
| 3 | import { defineConfig } from "vite"; |
| 4 | |
| 5 | // React Router RSC wired directly on @vitejs/plugin-rsc. Alchemy injects the |
| 6 | // distilled Cloudflare Vite plugin at build/dev time through Cloudflare.Vite. |
| 7 | export default defineConfig({ |
| 8 | clearScreen: false, |
| 9 | build: { minify: false }, |
| 10 | plugins: [ |
| 11 | react(), |
| 12 | rsc({ |
| 13 | serverHandler: false, |
| 14 | entries: { |
| 15 | client: "./react-router-vite/entry.browser.tsx", |
| 16 | ssr: "./react-router-vite/entry.ssr.tsx", |
| 17 | rsc: "./react-router-vite/entry.worker.tsx", |
| 18 | }, |
| 19 | }), |
| 20 | ], |
| 21 | environments: { |
| 22 | // The Worker is the RSC environment. Alchemy passes this environment |
| 23 | // topology to the distilled plugin via Cloudflare.Vite. |
| 24 | rsc: { |
| 25 | build: { |
| 26 | rollupOptions: { |
| 27 | input: { "entry.worker": "./react-router-vite/entry.worker.tsx" }, |
| 28 | }, |
| 29 | }, |
| 30 | }, |
| 31 | // A second `ssr` input the worker loads on demand via |
| 32 | // loadModule("ssr", "worker-ssr") — alongside the framework's `index`. |
| 33 | ssr: { |
| 34 | build: { |
| 35 | rollupOptions: { |
| 36 | input: { "worker-ssr": "./react-router-vite/worker-ssr.tsx" }, |
| 37 | }, |
| 38 | }, |
| 39 | }, |
| 40 | }, |
| 41 | optimizeDeps: { |
| 42 | include: ["react-router", "react-router/internal/react-server-client"], |
| 43 | }, |
| 44 | }); |