// Copyright (c) 2026 Doforu // Copyright (c) 2026 Cloudflare, Inc. // Licensed under the Apache 2.0 license found in the LICENSE-APACHE file or at: // https://opensource.org/licenses/Apache-2.0 // Modifications Copyright (c) 2026 Doforu, distributed under the AGPL-3.0-only (see LICENSE). import { reactRouter } from "@react-router/dev/vite"; import { cloudflare } from "@cloudflare/vite-plugin"; import tailwindcss from "@tailwindcss/vite"; import { defineConfig } from "vite"; import tsconfigPaths from "vite-tsconfig-paths"; import { fileURLToPath } from "node:url"; import path from "node:path"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); export default defineConfig({ plugins: [ cloudflare({ viteEnvironment: { name: "ssr" } }), tailwindcss(), reactRouter(), tsconfigPaths(), ], resolve: { alias: { // Workers SSR runner can't load react/jsx-dev-runtime (CJS dev build). // jsxDEV in React 19 has the same signature as jsx, so re-export from jsx-runtime. "react/jsx-dev-runtime": path.resolve(__dirname, "shim/jsx-dev-runtime.js"), }, }, // Force React-dependent packages to share the same ESM React instance. // Without this, esbuild bundles CJS React (react/cjs/react.production.js) into // a separate chunk with exports.useContext, creating a conflicting second React. optimizeDeps: { include: [ "react", "react-dom", "react-dom/client", "react-router", "@cloudflare/kumo", "@phosphor-icons/react", "@tanstack/react-query", ], }, });