loom build turns a gallery into a static, client-only site you can host anywhere. Use it to embed a
live, interactive scene in a docs page instead of a screenshot.
pnpm exec loom build ~/code/my-ui --targets src/scenes --out dist-preview --base ./If your vite.config.ts already passes targets to loomPreview(), pnpm vite build produces the
same bundle. See Vite integration.
Flags
loom build [dir] --targets [glob] [--out <dir>] [--base <path>] [--no-assets]| Flag | Default | Notes |
|---|---|---|
--targets | required | Same as for preview. Without it: loom: `build` requires --targets [glob] (the static gallery is target-driven). |
--out | dist-preview | Resolved against the current directory, not the project dir. |
--base | ./ | Public path. The relative default lets the output be hosted anywhere. |
--no-assets | off | Skips the rbxassetid:// download. |
build doesn’t read loom.config.ts, so pass --targets every time.
Point --out at a directory only loom uses. Aiming it at your site’s whole public/ deletes
everything else in it.
What comes out
index.htmlassets/index-<hash>.js # shell + runtime + adapterassets/index-<hash>.css # gallery chromeassets/loom_layout_wasm_bg-<hash>.wasmassets/CardScene.loom-<hash>.js # one async chunk per targetassets/CounterScene.loom-<hash>.jsassets/roboto-latin-400-normal-<hash>.woff2 # …and ~110 more- Each target is its own lazy chunk, so a page loads only the scene it shows.
- The
.wasmlayout engine is about 205 kB (78 kB gzipped), fetched once and cached. - The engine’s typefaces add ~2.8 MB across ~110 files. A browser fetches only the families and scripts a scene paints with.
The Roblox globals load before any scene code, so a built gallery never throws
UDim2 is not defined.
rbxassetid:// in a static build
A static host has no server to resolve asset ids, so the build does it ahead of time. It downloads each image into the output and writes a manifest the page reads:
__loom/assets.json # { "6031075938": "__loom/asset/6031075938.png" }__loom/asset/6031075938.png # the downloaded imageImage="rbxassetid://6031075938" then loads from your own origin, with no request to Roblox.
The build finds ids two ways. It scans the output for rbxassetid://<digits>. It also mounts every
target in node and reads the images in its tree, which catches ids built at runtime like
`rbxassetid://${iconId}`.
- Only the first render is baked. An image that appears later, behind a hover or after a fetch,
stays unresolved. Give it a real URL, or install your own
setImageResolver. - Mounting targets only happens in gallery builds. A build with a single client
entryonly scans. - An image never fails the build. An id that won’t resolve, or a target that won’t render, is warned about and left out.
To keep a build off the network, turn the download off: loomPreview({ assets: false }),
loom build --no-assets, or assets: false on buildGallery and withLoomGallery.
The URL contract
The built page reads six query parameters. This is the whole embedding API.
| Parameter | Values | Effect |
|---|---|---|
target | a target’s relative path, URL-encoded | Mounts that target on load. |
chrome | none | Hides the sidebar and shows one target full-bleed. Any other value keeps the sidebar. |
theme | light | dark | Sets the stage background and seeds PlayerGui.LoomTheme. Anything but light means dark. |
background | a CSS color | Paints the stage backdrop, overriding the theme’s. See below. |
base | px (bare ?base is 960), or none / off / 0 | Lays the scene out at this width and scales it to fit, instead of reflowing. Off by default. See Previews on a phone. |
debug | present, or 0/false/off/no/none for off | Opens the debug panel on load. A bare ?debug means on. |
/loom-preview/index.html?target=src%2Fscenes%2FCounter.loom.tsx&chrome=none&theme=lightWith chrome=none, the page always shows the ?target= scene. With the sidebar, the page routes by
#/<relPath> and ?target= only picks the first scene.
?debug=1 is the only way to open the debug panel in a chrome=none embed. An embed doesn’t
remember the panel between reloads.
?background= for a backdrop that is not either theme
theme sets the whole palette. background changes only the backdrop. For a white stage under the
light palette, use ?theme=light&background=white. Use transparent to show the host page through.
?background=#ffffff never reaches the gallery, because # starts the URL fragment. Write
%23ffffff or just ffffff.
Only colors are accepted: hex, a color name, and functional forms like rgb(...). A gradient or
url(...) is ignored and the theme’s backdrop stays. The backdrop is set before first paint, so an
embed never flashes the dark default.
Live theme switching
A host page can change a loaded frame’s theme without reloading it:
// GALLERY_ORIGIN is where the built gallery is served from — same-origin// embeds can use window.location.origin.frame.contentWindow.postMessage( { type: "loom-theme", theme: "dark" }, GALLERY_ORIGIN,);The backdrop works the same way:
frame.contentWindow.postMessage( { type: "loom-background", background: "#0b0d10" }, GALLERY_ORIGIN,);
// With no colour, the backdrop goes back to whatever the theme paints.frame.contentWindow.postMessage({ type: "loom-background" }, GALLERY_ORIGIN);The gallery listens for these two messages and ignores everything else.
Pass the gallery’s origin, not "*". The gallery doesn’t check event.origin, so if you fork the
shell and add messages that do more than repaint, add an origin check.
A theme change also writes LoomTheme onto Players.LocalPlayer.PlayerGui. A scene can follow the
host page’s theme with plain Roblox APIs:
const playerGui = Players.LocalPlayer.WaitForChild("PlayerGui");const [theme, setTheme] = useState(playerGui.LoomTheme ?? "dark");
useEffect(() => { const conn = playerGui .GetPropertyChangedSignal("LoomTheme") .Connect(() => setTheme(playerGui.LoomTheme)); return () => conn.Disconnect();}, []);A working embed pipeline
Running loom build before each site build works, but the output goes stale whenever a scene
changes, and you get no hot reload. If your site uses Vite, mount the gallery instead with
loom-dev/embed. For a Next.js site, use
Next.js integration.
This Astro integration serves the gallery in dev and builds it next to the site:
import { buildGallery, createGalleryServer, findGalleryTargets } from "loom-dev/embed";
export default function loomPreview(): AstroIntegration { let gallery; return { name: "loom-preview", hooks: { // Dev: Loom's own Vite server, mounted under the site's base. "astro:server:setup": async ({ server }) => { gallery = await createGalleryServer({ root: latticeApp, targets: "src/preview-targets", base: "/loom-preview/", }); server.middlewares.use(gallery.middleware); }, "astro:server:done": async () => await gallery?.close(),
// Build: the same gallery, emitted next to the site's own output. "astro:build:done": async ({ dir }) => { await buildGallery({ root: latticeApp, targets: "src/preview-targets", outDir: fileURLToPath(new URL("loom-preview/", dir)), }); }, }, };}Editing a scene hot-reloads the frame in the docs page, and no generated bundle lives in the repo. Some tips:
- Mount under your site’s own base path rather than a hard-coded
/loom-preview/, so previews still work if the site moves to a subpath. - Skip previews when the component project is missing, instead of failing. Fresh clones and CI
still build.
findGalleryTargets()tells you whether there is anything to serve without starting a server. Use an env var to make it strict for deploys. - Set iframe
srclazily, for example with anIntersectionObserver, and append&theme=from the site’s current theme. Push later theme changes withpostMessage.
For a host that isn’t a Vite app, such as a Hugo or Jekyll site, use loom build. Its output is
identical to buildGallery().
Error containment survives the build
Each target keeps its own error boundary in a built gallery. A target that throws shows an inline error panel with its stack, and the rest of the page keeps working.