import { defineConfig } from "vite"; import { svelte } from "@sveltejs/vite-plugin-svelte"; import { viteStaticCopy } from "vite-plugin-static-copy"; const host = process.env.TAURI_DEV_HOST; export default defineConfig(async () => ({ plugins: [ svelte(), viteStaticCopy({ targets: [ { src: "src/assets/fonts/*", dest: "fonts" }, ], }), ], clearScreen: false, server: { port: 1430, strictPort: true, // Always bind to IPv4 127.0.0.1 explicitly. `host || false` lets // vite pick "localhost" which on macOS resolves to both v4 and v6 // and binds to v6 by default — the Tauri webview then tries v4 // first and gets a connection refused. The explicit v4 address // matches `tauri.conf.json`'s `devUrl` so the webview connects // reliably. HMR via Tauri (cross-platform) still works because // vite binds both v4 and v6 in modern versions when the address // is the v4 loopback; if that breaks for someone we can use // `0.0.0.0` to listen on all interfaces instead. host: host || "127.0.0.1", hmr: host ? { protocol: "ws", host, port: 1431 } : undefined, watch: { ignored: ["**/src-tauri/**"] }, }, envPrefix: ["VITE_", "TAURI_ENV_*"], build: { target: process.env.TAURI_ENV_PLATFORM === "windows" ? "chrome105" : "safari13", minify: !process.env.TAURI_ENV_DEBUG ? "esbuild" : false, sourcemap: !!process.env.TAURI_ENV_DEBUG, }, }));