when-am-i / files / vite.config.ts
vite.config.ts
60741172 2026-06-17 Pavel Safronov | 1 | /// <reference types="vitest/config" /> |
e6fe2bc7 2026-06-17 Pavel Safronov | 2 | import { execSync } from 'node:child_process'; |
| 3 | import { readFileSync } from 'node:fs'; | |
edbab6ce 2026-03-20 Pavel Safronov | 4 | import { defineConfig } from 'vite'; |
| 5 | import react from '@vitejs/plugin-react'; | |
c2d75cfd 2026-10-27 Pavel Safronov | 6 | import fuzzyworld from 'fuzzyworld-tools/vite'; |
edbab6ce 2026-03-20 Pavel Safronov | 7 | |
e6fe2bc7 2026-06-17 Pavel Safronov | 8 | // Build metadata, surfaced in error reports so we know which deployed build a |
| 9 | // report came from. Commit falls back to "unknown" outside a git checkout (CI | |
| 10 | // without history, tarball builds, etc.). | |
| 11 | const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf-8')); | |
| 12 | const gitCommit = (() => { | |
| 13 | if (process.env.CI_COMMIT_SHORT_SHA) return process.env.CI_COMMIT_SHORT_SHA; | |
| 14 | try { | |
| 15 | return execSync('git rev-parse --short HEAD').toString().trim(); | |
| 16 | } catch { | |
| 17 | return 'unknown'; | |
| 18 | } | |
| 19 | })(); | |
| 20 | ||
edbab6ce 2026-03-20 Pavel Safronov | 21 | export default defineConfig({ |
c2d75cfd 2026-10-27 Pavel Safronov | 22 | plugins: [fuzzyworld(), react()], |
e6fe2bc7 2026-06-17 Pavel Safronov | 23 | define: { |
| 24 | __APP_VERSION__: JSON.stringify(pkg.version), | |
| 25 | __GIT_COMMIT__: JSON.stringify(gitCommit), | |
| 26 | __BUILD_TIME__: JSON.stringify(new Date().toISOString()), | |
| 27 | }, | |
60741172 2026-06-17 Pavel Safronov | 28 | server: { |
| 29 | // Bind/open on 127.0.0.1 rather than `localhost`. Some browsers (e.g. | |
| 30 | // Firefox here) pin `localhost` to HTTPS via HSTS — set by other local | |
| 31 | // projects that serve HTTPS dev servers — and then force-upgrade every | |
| 32 | // http://localhost request, which fails against Vite's plain-HTTP dev | |
| 33 | // server (NS_ERROR_NET_EMPTY_RESPONSE). HSTS is per-hostname, so | |
| 34 | // 127.0.0.1 is unaffected. A CLI `--host` still overrides this. | |
| 35 | host: '127.0.0.1', | |
| 36 | }, | |
edbab6ce 2026-03-20 Pavel Safronov | 37 | build: { |
| 38 | outDir: 'dist', | |
| 39 | }, | |
60741172 2026-06-17 Pavel Safronov | 40 | test: { |
| 41 | // Engine tests are pure (no DOM); the default node environment is fine. | |
| 42 | environment: 'node', | |
| 43 | include: ['src/**/*.test.ts'], | |
| 44 | }, | |
edbab6ce 2026-03-20 Pavel Safronov | 45 | }); |