import tailwindcss from "@tailwindcss/vite"; import react from "@vitejs/plugin-react"; import { defineConfig } from "vite"; // @ts-expect-error process is a nodejs global const host = process.env.TAURI_DEV_HOST; // https://vite.dev/config/ export default defineConfig(async () => ({ plugins: [tailwindcss(), react()], // Force esbuild to tree-shake as little as possible from monaco-editor. // By default, Vite's pre-bundling applies tree-shaking which discards // `monaco.languages.createDiagnosticCollection` and other standalone-editor // services that we need at runtime. optimizeDeps: { esbuildOptions: { treeShaking: false, }, }, // Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build` // // 1. prevent Vite from obscuring rust errors clearScreen: false, // 2. tauri expects a fixed port, fail if that port is not available server: { port: 1420, strictPort: true, host: host || false, hmr: host ? { protocol: "ws", host, port: 1421, } : undefined, watch: { // 3. tell Vite to ignore watching `src-tauri` ignored: ["**/src-tauri/**"], }, // Dev proxy: the SPA talks to the backend via relative URLs so that the // same code works in dev (Vite :1420 → backend :4000) and in self-hosted // prod (behind a reverse proxy). The preview webview and its WS are also // proxied so the iframe is same-origin with the app. proxy: { "/api": "http://localhost:4000", "/preview-app": { target: "http://localhost:4000", // the webview is HTML; rewrite so the path is preserved for upstream ws: false, }, "/lsp": { target: "ws://localhost:4000", ws: true }, "/preview": { target: "ws://localhost:4000", ws: true }, }, }, }));