Skip to content

build-site.mjs

Builds the game client into dist/ and stamps it with the commit and branch it was built from.

Contributor toolingbuild-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 build

The equivalent direct form:

bash
node scripts/build-site.mjs

Options

No options.

Inputs and outputs

Reads:

  • the app/ source tree, built by vite's own node_modules/vite/bin/vite.js build app
  • git, for the branch and short SHA — GITHUB_REF_NAME or CI_COMMIT_BRANCH first, then git rev-parse, falling back to local/detached if git itself fails rather than erroring

Writes:

  • dist/ — vite's build output, emptied and rebuilt on every run (app/vite.config.mjs sets emptyOutDir: true)
  • every .html, .mjs, .js, .css, .json, .svg, or .txt file under dist/ 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 build

Build, then preview the exact bytes a deploy would ship, locally and statically:

bash
npm run build && npm run play

Notes

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