Skip to content

Build & Deployment Internals

How the three build outputs are produced. If you only want to deploy modernGraphTool, see Guide for Operators → Choosing a Deployment instead — this page is about how the build itself works.

CommandOutputWhat it is
npm run builddist/Static SPA, prerendered, SPA fallback via .htaccess
npm run build:cdndist-cdn/Thin loader for jsDelivr-hosted assets
npm run build:site-templatedist-site-template/The GitHub Pages template repo

The CDN build emits a thin cdn-index.html loader plus cdn/loader.js; set MGT_CDN_BASE to rewrite the _app/ URLs.

scripts/generate-boot-manifest.js writes boot.json: the entry URLs, plus an integrity map with a sha384 hash for every script and stylesheet under _app/. deploy.yml publishes to the cdn branch in three commits and never rewrites its history:

  1. the release’s _app/ files, which boot.json then addresses by that commit;
  2. v{version}/boot.json, loader.js (minified by scripts/minify-loader.js; cdn/loader.js stays the readable source) and versions.json. versions.json maps each major to its release and, under boot, embeds that release’s manifest so the loader needs one request instead of two;
  3. pins.json, which records commit 2 and the hashes of loader.js and boot.json for operators who pin a release (scripts/write-cdn-pins.js; the same snippet lands in the workflow run’s summary).

loader.js reaches every unpinned CDN site the moment it is pushed, and pinned sites keep the loader they pinned, so a change to boot.json or versions.json has to stay readable by older loaders: add keys, never repurpose one.

npm run build and npm run build:cdn both run scripts/preload-boot-chunks.js on the built index.html. It adds a <link rel="modulepreload"> for every script the first screen needs that SvelteKit’s own list leaves out, so the browser fetches them all in one round trip:

  • The route nodes. The fallback page knows no route, so SvelteKit lists only the root layout. Since SvelteKit 3 the router asks for the page node after the app chunk has loaded and run, which cost about 55 ms in the startup benchmark.
  • Chunks shared with a lazy chunk. Code used by both the app chunk and a dynamically imported one (the Equalizer panel, Hardware EQ) is split into its own chunk, which the app chunk imports statically.

The script follows the static imports of the built files, so a new lazy chunk needs no change here. boot.json takes its preload list from the same page. After a change to what loads lazily, run node scripts/bench-startup/waterfall.mjs and check that no script starts only after a larger one has finished.

scripts/csp.js builds the Content-Security-Policy that releases ship switched off. It hashes the inline scripts of the page an operator will serve and replaces the __CSP__ token:

BuildPage hashedWritten to
npm run builddist/index.htmldist/.htaccess
npm run build:cdncdn-index.htmldist-cdn/.htaccess, cdn-index.html’s meta
npm run build:site-templatesite-template/index.htmlthat page’s meta

npm run test:smoke reads the commented Header set lines back out of dist/.htaccess and sends them, so the full build’s policy is exercised on every CI run. The CDN shells’ policy is not: it needs the published app on jsDelivr. What operators have to add for their own customizations is listed on Security Headers.

A Vite plugin serves defaults/ as a fallback during development and copies its contents into dist/ at build time — without overwriting files that already exist under static/. That is how an operator’s local customizations survive an upgrade.

Files an operator is expected to edit in dist/: config.js, theme.css, data/, assets/strings/.

potatosalad775/modernGraphTool_site is a separate repository that operators copy with “Use this template”.

It is generated output, not a hand-maintained repo. npm run build:site-template assembles it, and .github/workflows/sync-site-template.yml force-syncs the result on every push to main that touches defaults/, site-template/, or the script. Edit the sources in the main repo — anything committed straight to the template repo is overwritten on the next sync.

  • Most of it is defaults/ verbatim (theme.css, data/, assets/), which is the whole reason the sync exists — that content drifts the moment defaults/ changes.
  • config.js is defaults/config.js with the commented CDN_MODE stub spliced out and site-template/config-cdn-mode.js spliced in, so new config options reach the template for free. The splice is anchored on the stub’s first and last lines and throws if it stops matching — a template with no live CDN_MODE is a blank page, since its index.html is only a loader. That file is a JS fragment, so it sits in .prettierignore and ESLint’s ignores; the generated config.js is syntax-checked by the build script instead.
  • site-template/index.html is source, not derived from cdn/cdn-index.html — keep the shared parts in sync by hand. Two deliberate divergences:
    1. It always loads loader.js from jsDelivr (no localhost branch — operators never iterate on the loader).
    2. It carries an inline base-path detector that sets CDN_MODE.BASE_PATH from the first path segment on *.github.io hosts, so both username.github.io/<repo>/ and username.github.io/ work with no config edit, and a repo rename survives. It defers to an explicit BASE_PATH. This lives in the template rather than in cdn/loader.js because a loader change only reaches deployments after the next cdn branch publish.
  • The workflow needs a SITE_TEMPLATE_TOKEN secret (fine-grained PAT, Contents: write on the template repo) — GITHUB_TOKEN cannot push across repositories.