fuzzyworld

when-am-i / files / vite.config.ts

vite.config.ts

1.7 KB · history · blame

1/// <reference types="vitest/config" />
2import { execSync } from 'node:child_process';
3import { readFileSync } from 'node:fs';
4import { defineConfig } from 'vite';
5import react from '@vitejs/plugin-react';
6import fuzzyworld from 'fuzzyworld-tools/vite';
7
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.).
11const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf-8'));
12const 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
21export default defineConfig({
22 plugins: [fuzzyworld(), react()],
23 define: {
24 __APP_VERSION__: JSON.stringify(pkg.version),
25 __GIT_COMMIT__: JSON.stringify(gitCommit),
26 __BUILD_TIME__: JSON.stringify(new Date().toISOString()),
27 },
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 },
37 build: {
38 outDir: 'dist',
39 },
40 test: {
41 // Engine tests are pure (no DOM); the default node environment is fine.
42 environment: 'node',
43 include: ['src/**/*.test.ts'],
44 },
45});