43 lines · 1.4 KB · TypeScript
RawDownload
import { defineConfig, type Plugin } from "vite";import { cloudflare } from "@cloudflare/vite-plugin";import { tanstackStart } from "@tanstack/react-start/plugin/vite";import react from "@vitejs/plugin-react";import tailwindcss from "@tailwindcss/vite"; // Dev-only: the cloudflare vite-plugin bridges outbound fetches (JWKS,// OAuth metadata proxy, etc.) through node undici in the host process. If// a pooled keep-alive socket gets RST'd while no listener is attached, the// `'error'` emit is unhandled and tears down the whole dev server. Log// enough to identify the offender and keep the server alive.const devCrashGuard = (): Plugin => {  let installed = false;  const install = () => {    if (installed) return;    installed = true;    process.on("uncaughtException", (err, origin) => {      console.error(        `[dev-crash-guard] uncaughtException (origin=${origin}):`,        err,      );    });    process.on("unhandledRejection", (reason, promise) => {      console.error("[dev-crash-guard] unhandledRejection:", reason, promise);    });  };  return {    name: "dev-crash-guard",    apply: "serve",    configureServer: install,  };}; export default defineConfig({  resolve: { tsconfigPaths: true },  plugins: [    devCrashGuard(),    tailwindcss(),    cloudflare({ viteEnvironment: { name: "ssr" }, inspectorPort: false }),    tanstackStart(),    react(),  ],});