Appearance
build-site.mjs
Builds the game client into dist/ and stamps it with the commit and branch it was built from.
Contributor tooling › build-site.mjs
What it does
Runs vite's production build of app into dist/, exiting before touching anything else if the build fails or emits no index.html under dist/. Reads the build's commit SHA, ISO build time, and branch name, then rewrites every text file under dist/ that contains one of those tokens with the real value.
Usage
The minimal invocation that works:
bash
npm run buildThe equivalent direct form:
bash
node scripts/build-site.mjsOptions
No options.
Inputs and outputs
Reads:
- the
app/source tree, built by vite's ownnode_modules/vite/bin/vite.js build app - git, for the branch and short SHA —
GITHUB_REF_NAMEorCI_COMMIT_BRANCHfirst, thengit rev-parse, falling back tolocal/detachedif git itself fails rather than erroring
Writes:
dist/— vite's build output, emptied and rebuilt on every run (app/vite.config.mjssetsemptyOutDir: true)- every
.html,.mjs,.js,.css,.json,.svg, or.txtfile underdist/that contains__GW_BUILD__,__GW_BRANCH__, or__GW_BUILT_AT__, rewritten in place with the real values
On success, prints a one-line summary: file count, how many were stamped, the build token, and the branch. Exit codes: 0 on success; 1 if vite's build exits non-zero, or if it emits no index.html under dist/.
Examples
Build the site on its own, e.g. before a deploy — both deploy-staging.mjs and deploy-prod.mjs run this first and refuse to deploy if it fails:
bash
npm run buildBuild, then preview the exact bytes a deploy would ship, locally and statically:
bash
npm run build && npm run playNotes
If git itself fails (no repository, no commits), the stamp silently falls back to SHA local and branch detached rather than erroring. A dist/ stamped that way did not fail the build, but its tokens do not identify a real commit.
Source
scripts/build-site.mjs — part of Contributor tooling