Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
76 lines (71 loc) · 3.61 KB
/
Copy pathvite.config.ts
File metadata and controls
76 lines (71 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2026 Tobias Bäumer — part of Codeenstein 3D (see LICENSE)
import { execSync } from "node:child_process";
import { fileURLToPath } from "node:url";
import { defineConfig } from "vite";
const emptyNodeShim = fileURLToPath(new URL("./src/empty-node-shim.ts", import.meta.url));
/** `YYYY-MM-DD HH:MM`, local to the machine running `vite build`/`vite dev` —
* baked into the bundle as `__BUILD_TIME__` (see `vite-env.d.ts`) so the page
* title can show which build is actually loaded, e.g. to catch a stale cached
* bundle after a deploy. For `vite dev` this is just "when the dev server
* started", not a live-updating clock — computed once when the config loads. */
function buildTimestamp(): string {
const now = new Date();
const pad = (n: number) => String(n).padStart(2, "0");
return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())} ${pad(now.getHours())}:${pad(now.getMinutes())}`;
}
/** `HEAD`'s exact tag (e.g. a release build) if it has one, otherwise its
* short commit hash — baked into the bundle as `__BUILD_REF__` alongside
* `__BUILD_TIME__` so the page title also pins down *which* commit is
* actually loaded, not just when it was built. Falls back to "unknown" if
* git isn't available at all (e.g. building from a source tarball with no
* `.git` directory) rather than failing the whole build over a title detail. */
function buildRef(): string {
const run = (cmd: string) => execSync(cmd, { stdio: ["ignore", "pipe", "ignore"] }).toString().trim();
try {
return run("git describe --tags --exact-match");
} catch {
try {
return run("git rev-parse --short HEAD");
} catch {
return "unknown";
}
}
}
export default defineConfig({
define: {
__BUILD_TIME__: JSON.stringify(buildTimestamp()),
__BUILD_REF__: JSON.stringify(buildRef()),
},
server: {
// Automated headless scripts (`scripts/lib/multiplayerTestServers.mjs`)
// spin up their own throwaway dev server purely to serve static assets
// for one short-lived Playwright session — no HMR/live-reload is ever
// needed there, and Vite's own file watcher (chokidar/inotify) can hit
// a real `ENOSPC` ("system limit for number of file watchers reached")
// wall on a host where something else (Dropbox, other sync/indexing
// tools) already consumes a big share of the OS-wide inotify watch
// budget — confirmed directly against a real SSH-lane host, where
// raising the sysctl limit wouldn't have been a real fix (Dropbox's own
// usage there scales with however much it's syncing, not a fixed
// amount). `CODEENSTEIN_VITE_NO_WATCH` opts out of the watcher entirely
// for exactly that case; unset (the default) for a normal `npm run dev`
// keeps full HMR.
watch: process.env.CODEENSTEIN_VITE_NO_WATCH ? null : undefined,
},
resolve: {
alias: {
// web-tree-sitter's single build (web-tree-sitter.js) statically
// imports `fs/promises` and `module` for its Node.js code path, even
// though that path never actually runs in a browser (see
// `src/empty-node-shim.ts`) — Vite's bundler still has to resolve the
// import at build time, which without this produced "has been
// externalized for browser compatibility" warnings on every production
// build. Aliased to an absolute path (not the "/src/..." root-relative
// form) since esbuild's dev-time dependency pre-bundling resolves that
// against the OS filesystem root, not the project root, and fails.
"fs/promises": emptyNodeShim,
module: emptyNodeShim,
},
},
});