diff --git a/README.md b/README.md index 7dd3805..898d1e8 100644 --- a/README.md +++ b/README.md @@ -155,6 +155,38 @@ parameters a viewer actually notices, and morphing cannot interpolate them, so before the split they were pinned for the whole beat and the tour looked static. +## Publish the viewer + +```sh +bun run site:build # → dist-viewer/, ready for any static host +``` + +The output is the viewer at a domain root: an `index.html`, a `viewer.js` and a +`viewer.css` it loads by absolute path. Nothing is fetched at run time — the +registry address in the sidebar is a label, not a request — so there is no API +to stand up and nothing to 404. + +Beside it is `artifact.html`, the same viewer collapsed into one self-contained +file. That is the one to hand to anyone who wants it without a server. + +| Host | Free with a PRIVATE repo | Build command | Output | +| --- | :-: | --- | --- | +| Vercel | yes | `bun run site:build` | `dist-viewer` | +| Cloudflare Pages | yes | `bun run site:build` | `dist-viewer` | +| GitHub Pages | **no** — needs Pro | — | — | + +`vercel.json` already carries the first row, so Vercel needs the repository +imported and nothing else. GitHub Pages is in the table because it is the +obvious guess and the answer is no: on the free plan Pages serves public +repositories only, so it costs either a subscription or making the source +public. + +One thing worth being deliberate about rather than discovering later: +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 — but it is not nothing, and a page anyone can open is a +page anyone can read. + ## Layout ```text diff --git a/package.json b/package.json index 842228c..07fb7b0 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "registry:build": "bun my-registry/build.ts", "registry:validate": "vibe3d registry validate my-registry/dist/registry.json", "viewer:build": "vite build --config vite.viewer.config.ts && bun scripts/build-artifact.ts", + "site:build": "bun run registry:build && bun run viewer:build && bun scripts/build-site.ts", "verify:glb": "bun scripts/verify-glb.ts", "render": "bun scripts/render.ts", "export:glb": "bun scripts/export-glb.ts" diff --git a/scripts/build-site.ts b/scripts/build-site.ts new file mode 100644 index 0000000..5c35a02 --- /dev/null +++ b/scripts/build-site.ts @@ -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(' · ')}`) diff --git a/vercel.json b/vercel.json new file mode 100644 index 0000000..7267fa6 --- /dev/null +++ b/vercel.json @@ -0,0 +1,16 @@ +{ + "$schema": "https://openapi.vercel.sh/vercel.json", + "buildCommand": "bun run site:build", + "outputDirectory": "dist-viewer", + "installCommand": "bun install --frozen-lockfile", + "framework": null, + "cleanUrls": true, + "headers": [ + { + "source": "/viewer.(js|css)", + "headers": [ + { "key": "Cache-Control", "value": "public, max-age=31536000, immutable" } + ] + } + ] +}