import { fileURLToPath, URL } from "node:url" import tailwindcss from "@tailwindcss/vite" import { tanstackStart } from "@tanstack/react-start/plugin/vite" import viteReact from "@vitejs/plugin-react" import { nitro } from "nitro/vite" import { defineConfig, searchForWorkspaceRoot } from "vite" // Les packages @wp-reactor/* se résolvent par node_modules : symlinks workspace // (source `src/index.ts` via leurs `exports`) en dogfood, paquets publiés chez // un vrai client. Aucun alias relatif — sinon on suppose une topologie de repo. export default defineConfig(({ command }) => ({ // Les .env vivent à la racine du repo client (apps/webapp → ../..). envDir: "../..", ...(command !== "build" ? {} : { ssr: { noExternal: true, resolve: { conditions: ["import", "module", "default"], }, }, }), resolve: { alias: { "@": fileURLToPath(new URL("./src", import.meta.url)), }, }, server: { allowedHosts: process.env.VITE_ALLOWED_HOST ? [process.env.VITE_ALLOWED_HOST] : [], watch: { usePolling: process.env.CHOKIDAR_USEPOLLING === "true", interval: 300, }, fs: { // `../..` = racine du repo client (cas nominal). On ajoute la racine de // workspace détectée par Vite : en dogfood, le store pnpm est hissé au // monorepo framework, AU-DESSUS de la sandbox → sinon Vite bloque le // chargement des deps (ex. @tanstack/react-start) hors de l'allow-list. allow: [ searchForWorkspaceRoot(process.cwd()), fileURLToPath(new URL("../..", import.meta.url)), ], }, }, plugins: [nitro(), tailwindcss(), tanstackStart(), viteReact()], }))