import { defineConfig } from "vite"; import { svelte } from "@sveltejs/vite-plugin-svelte"; // `tauri android dev` sets this to the machine's LAN address so the phone's // webview can reach the dev server; on the desktop it is unset and the // loopback rule below stands. const devHost = process.env.TAURI_DEV_HOST; export default defineConfig({ plugins: [svelte()], clearScreen: false, build: { rollupOptions: { // Three documents, one app: the full shell, the mini player // window and the phone load the same modules through different // mount points. input: { main: "index.html", mini: "mini.html", mobile: "mobile.html", }, }, }, server: { port: 1421, strictPort: true, // Bind IPv4 loopback explicitly. With no host, Vite on modern Node // binds [::1] ONLY, while WebView2 resolves the devUrl's "localhost" // to 127.0.0.1 — so the window opens on ERR_CONNECTION_REFUSED while // curl and the browser (which try ::1) both say the server is fine. host: devHost || "127.0.0.1", // Named explicitly, not left to the page's host: on the phone the dev // flavour is proxied under http://tauri.localhost (ANDROID.md), where // Vite's client would first knock on ws://tauri.localhost and log a // refused connection before falling back. localhost is right in both // places — WebView2 here, the adb reverse tunnel there. hmr: devHost ? { protocol: "ws", host: devHost, port: 1421 } : { protocol: "ws", host: "localhost", port: 1421 }, watch: { // Never watch the Rust build dir: cargo locks files mid-compile, // which crashes Vite's watcher (EBUSY) and kills tauri dev. ignored: ["**/src-tauri/**", "**/crates/**", "**/target/**"], }, }, });