| 1 | import { defineConfig } from "vite"; |
| 2 | import react from "@vitejs/plugin-react"; |
| 3 | import { internalIpV4 } from "internal-ip"; |
| 4 | |
| 5 | // @ts-expect-error process is a nodejs global |
| 6 | const mobile = !!/android|ios/.exec(process.env.TAURI_ENV_PLATFORM); |
| 7 | |
| 8 | // https://vitejs.dev/config/ |
| 9 | export default defineConfig(async () => ({ |
| 10 | plugins: [react()], |
| 11 | |
| 12 | // Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build` |
| 13 | // |
| 14 | // 1. prevent vite from obscuring rust errors |
| 15 | clearScreen: false, |
| 16 | // 2. tauri expects a fixed port, fail if that port is not available |
| 17 | server: { |
| 18 | port: 1420, |
| 19 | strictPort: true, |
| 20 | host: mobile ? "0.0.0.0" : false, |
| 21 | hmr: mobile |
| 22 | ? { |
| 23 | protocol: "ws", |
| 24 | host: await internalIpV4(), |
| 25 | port: 1421, |
| 26 | } |
| 27 | : undefined, |
| 28 | watch: { |
| 29 | // 3. tell vite to ignore watching `src-tauri` |
| 30 | ignored: ["**/src-tauri/**"], |
| 31 | }, |
| 32 | }, |
| 33 | })); |