Make the viewer publishable as a static site
`bun run site:build` and the output is a site: the viewer at a domain root, with an `index.html` a host can answer `/` with. The viewer build already emitted everything else — `viewer.js` and `viewer.css` loaded by absolute path, which is correct at a root and wrong nowhere — but it emitted no index, so a static host serving the directory answered `/` with a 404 and the site would have looked broken while every file on it was fine. The landing page is the VIEWER rather than the demo app, which is the one decision in the script and the reason it is a script: someone arriving at the address should be able to turn a model over and press play, not read a page about a model they cannot see. Verified the way a host would see it rather than through the dev server: built, served from the directory as a root, and every one of the page's own requests came back 200 — `/`, `/viewer.js`, `/viewer.css` — with a clean console and all 38 models in the rail. Nothing is fetched at run time, either; the registry address in the sidebar is a label, not a request, so there is no API to stand up. `vercel.json` carries the build command, the output directory and a year of immutable caching on the two hashed assets. Cloudflare Pages takes the same two settings in its dashboard. GitHub Pages is in the README's table with a "no" against it, because it is the obvious guess and the answer costs money: on the free plan Pages serves public repositories only. Worth stating where someone will look for it rather than leaving them to find out. And one line that is a decision rather than a fact, so it is written down: publishing the viewer publishes the models. The bundle carries every builder in it, minified. That is a different thing from the npm package — which ships the source AS source, comments and all — but it is not nothing.
This commit is contained in:
parent
4502f3fad6
commit
7157c928c8
4 changed files with 84 additions and 0 deletions
35
scripts/build-site.ts
Normal file
35
scripts/build-site.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
* Builds the published site: the viewer, at a domain root.
|
||||
*
|
||||
* The viewer build already emits everything a host needs — `viewer.html` plus
|
||||
* a `viewer.js` and a `viewer.css` it loads by absolute path, which is correct
|
||||
* at the root of a domain and wrong nowhere. What it does not emit is an
|
||||
* `index.html`, so a static host serving the directory answers `/` with a 404
|
||||
* and the site looks broken while every file on it is fine.
|
||||
*
|
||||
* So this is a copy, and it is a script rather than a line in `package.json`
|
||||
* because there is a decision in it: the site's landing page is the VIEWER,
|
||||
* not the demo app. Someone arriving at the address should be able to turn a
|
||||
* model over and press play, not read a page about a model they cannot see.
|
||||
*
|
||||
* `artifact.html` is left beside it. It is the same viewer collapsed into one
|
||||
* self-contained file, which is what to hand anyone who wants the thing
|
||||
* without a server — a VDS, an email, a USB stick.
|
||||
*
|
||||
* bun run site:build → dist-viewer/, ready for any static host
|
||||
*/
|
||||
import { copyFile, stat } from 'node:fs/promises'
|
||||
|
||||
const from = 'dist-viewer/viewer.html'
|
||||
const to = 'dist-viewer/index.html'
|
||||
|
||||
await copyFile(from, to)
|
||||
|
||||
const sizes = await Promise.all(
|
||||
['index.html', 'viewer.js', 'viewer.css', 'artifact.html'].map(async (name) => {
|
||||
const info = await stat(`dist-viewer/${name}`)
|
||||
return `${name} ${Math.round(info.size / 1024)} KB`
|
||||
}),
|
||||
)
|
||||
|
||||
console.log(`dist-viewer/ ready — ${sizes.join(' · ')}`)
|
||||
Loading…
Add table
Add a link
Reference in a new issue