Skip to content

The platform for continuously improving AI agents.

2.8 KB
Raw Blame
/// <reference types="vitest/config" />
import { fileURLToPath, URL } from "node:url";
import tailwindcss from "@tailwindcss/vite";
import { tanstackRouter } from "@tanstack/router-plugin/vite";
import viteReact from "@vitejs/plugin-react";
import { defineConfig } from "vite";

const isVitest = Boolean(process.env.VITEST);

const config = defineConfig({
  optimizeDeps: {
    // The syntax catalogue ships ESM; prebundling every language exceeds the local dev
    // container memory budget.
    exclude: ["@streamdown/code", "shiki"],
    // Each icon is a separate subpath entry, so Vite would otherwise discover
    // them one-by-one as components mount and re-optimize mid-session. That
    // invalidates the ?v=<hash> URLs the browser already holds: "504 Outdated
    // Optimize Dep" → "Failed to fetch dynamically imported module".
    include: [
      "@lobehub/icons/es/Anthropic/components/Mono",
      "@lobehub/icons/es/Cohere/components/Color",
      "@lobehub/icons/es/Gemini/components/Color",
      "@lobehub/icons/es/Meta/components/Color",
      "@lobehub/icons/es/Mistral/components/Color",
      "@lobehub/icons/es/OpenAI/components/Mono",
      "@lobehub/icons/es/Qwen/components/Color",
      "@lobehub/icons/es/XAI/components/Mono",
    ],
  },
  plugins: [
    // Tailwind + route codegen are build/dev-only; under vitest they inflate
    // transform time without helping unit tests.
    ...(!isVitest
      ? [
          tailwindcss(),
          tanstackRouter({
            autoCodeSplitting: true,
            generatedRouteTree: "./src/routeTree.gen.ts",
            routesDirectory: "./src/routes",
            target: "react",
          }),
        ]
      : []),
    viteReact(),
  ],
  publicDir: "public",
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
    tsconfigPaths: true,
  },
  server: {
    proxy: {
      "/api.v1.": {
        changeOrigin: true,
        target: process.env.OTEL_URL ?? "http://127.0.0.1:4318",
      },
    },
  },
  test: {
    // Unbounded workers starve DOM tests on shared development and CI hosts.
    maxWorkers: 2,
    // Overrides the vitest 4 default of forks: threads cut wall time ~3–4× here
    // because import/transform dominate and share better across workers.
    pool: "threads",
    // zod v4's conditional CJS/ESM exports break vitest's default
    // externalization: the named `z` export doesn't survive interop
    // (`import { z } from "zod"` → undefined). Inlining routes zod through
    // vite's transform, as the app build already does.
    // @lobehub/ui imports @base-ui directories, which Node's ESM loader cannot resolve
    // without an index path; vite's resolver can.
    server: { deps: { inline: ["zod", "@lobehub/icons", "@lobehub/ui"] } },
    setupFiles: ["./src/test/setup.ts"],
  },
});

export default config;