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.
Outputs
Section titled “Outputs”| Command | Output | What it is |
|---|---|---|
npm run build | dist/ | Static SPA, prerendered, SPA fallback via .htaccess |
npm run build:cdn | dist-cdn/ | Thin loader for jsDelivr-hosted assets |
npm run build:site-template | dist-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:
- the release’s
_app/files, whichboot.jsonthen addresses by that commit; v{version}/boot.json,loader.js(minified byscripts/minify-loader.js;cdn/loader.jsstays the readable source) andversions.json.versions.jsonmaps each major to its release and, underboot, embeds that release’s manifest so the loader needs one request instead of two;pins.json, which records commit 2 and the hashes ofloader.jsandboot.jsonfor 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.
What the first screen preloads
Section titled “What the first screen preloads”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.
The recommended security headers
Section titled “The recommended security headers”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:
| Build | Page hashed | Written to |
|---|---|---|
npm run build | dist/index.html | dist/.htaccess |
npm run build:cdn | cdn-index.html | dist-cdn/.htaccess, cdn-index.html’s meta |
npm run build:site-template | site-template/index.html | that 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.
The defaults/ mechanism
Section titled “The defaults/ mechanism”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/.
GitHub Pages template
Section titled “GitHub Pages template”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 momentdefaults/changes. config.jsisdefaults/config.jswith the commentedCDN_MODEstub spliced out andsite-template/config-cdn-mode.jsspliced 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 liveCDN_MODEis a blank page, since itsindex.htmlis only a loader. That file is a JS fragment, so it sits in.prettierignoreand ESLint’s ignores; the generatedconfig.jsis syntax-checked by the build script instead.site-template/index.htmlis source, not derived fromcdn/cdn-index.html— keep the shared parts in sync by hand. Two deliberate divergences:- It always loads
loader.jsfrom jsDelivr (no localhost branch — operators never iterate on the loader). - It carries an inline base-path detector that sets
CDN_MODE.BASE_PATHfrom the first path segment on*.github.iohosts, so bothusername.github.io/<repo>/andusername.github.io/work with no config edit, and a repo rename survives. It defers to an explicitBASE_PATH. This lives in the template rather than incdn/loader.jsbecause a loader change only reaches deployments after the nextcdnbranch publish.
- It always loads
- The workflow needs a
SITE_TEMPLATE_TOKENsecret (fine-grained PAT,Contents: writeon the template repo) —GITHUB_TOKENcannot push across repositories.