import { defineConfig } from "vite"; import { sveltekit } from "@sveltejs/kit/vite"; import process from "node:process"; import { readFileSync } from "node:fs"; // The installer build sets RUNESTONE_VERSION. It writes package.json only after the build completes. const packageVersion = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8")).version; const appVersion = process.env.RUNESTONE_VERSION || packageVersion; const host = process.env.TAURI_DEV_HOST; const monacoCss = `${process.cwd().replaceAll("\\", "/")}/node_modules/monaco-editor/min/vs/editor/editor.main.css`; // https://vite.dev/config/ export default defineConfig(() => ({ plugins: [sveltekit()], define: { __RUNESTONE_VERSION__: JSON.stringify(appVersion), }, resolve: { alias: { "monaco-editor-css": monacoCss, }, }, optimizeDeps: { include: ["monaco-editor"], }, worker: { format: /** @type {"es"} */ ("es"), }, // 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 || "127.0.0.1", hmr: host ? { protocol: "ws", host, port: 1421, } : undefined, watch: { // 3. tell Vite to ignore watching `src-tauri` ignored: ["**/src-tauri/**", "**/fixtures/**", "**/.runestone/**", "**/.audit/**", "**/output/**", "**/browser-runtime/dist/**", "**/browser-runtime/output/**"], }, }, }));