Loomguides

Static builds and embedding

Bundle a gallery into a hostable SPA, then deep-link one scene per iframe.

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.

Build a gallery
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]
FlagDefaultNotes
--targetsrequiredSame as for preview. Without it: loom: `build` requires --targets [glob] (the static gallery is target-driven).
--outdist-previewResolved against the current directory, not the project dir.
--base./Public path. The relative default lets the output be hosted anywhere.
--no-assetsoffSkips the rbxassetid:// download.

build doesn’t read loom.config.ts, so pass --targets every time.

What comes out

dist-preview/
index.html
assets/index-<hash>.js # shell + runtime + adapter
assets/index-<hash>.css # gallery chrome
assets/loom_layout_wasm_bg-<hash>.wasm
assets/CardScene.loom-<hash>.js # one async chunk per target
assets/CounterScene.loom-<hash>.js
assets/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 .wasm layout 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:

dist-preview/
__loom/assets.json # { "6031075938": "__loom/asset/6031075938.png" }
__loom/asset/6031075938.png # the downloaded image

Image="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 entry only 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.

ParameterValuesEffect
targeta target’s relative path, URL-encodedMounts that target on load.
chromenoneHides the sidebar and shows one target full-bleed. Any other value keeps the sidebar.
themelight | darkSets the stage background and seeds PlayerGui.LoomTheme. Anything but light means dark.
backgrounda CSS colorPaints the stage backdrop, overriding the theme’s. See below.
basepx (bare ?base is 960), or none / off / 0Lays the scene out at this width and scales it to fit, instead of reflowing. Off by default. See Previews on a phone.
debugpresent, or 0/false/off/no/none for offOpens the debug panel on load. A bare ?debug means on.
Deep-link one scene, chromeless, light
/loom-preview/index.html?target=src%2Fscenes%2FCounter.loom.tsx&chrome=none&theme=light

With 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.

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:

From the embedding page
// 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:

Re-point the backdrop live
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.

A theme change also writes LoomTheme onto Players.LocalPlayer.PlayerGui. A scene can follow the host page’s theme with plain Roblox APIs:

A scene that follows the host page's theme
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:

src/integrations/loom-preview.ts (abridged)
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 src lazily, for example with an IntersectionObserver, and append &theme= from the site’s current theme. Push later theme changes with postMessage.

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.