loom — Roblox UI preview
Usage: loom preview [dir] [--port <n>] [--host] [--targets [glob]] loom build [dir] --targets [glob] [--out <dir>] [--base <path>] [--no-assets]Any other first argument, or none, prints this usage text and exits 0.
loom preview
Starts a Vite dev server with loomPreview() already applied. It runs with configFile: false, so
your project’s own vite.config.ts is ignored.
| Argument | Default | Rules |
|---|---|---|
dir | . | Positional, resolved against the working directory. A missing directory exits 1 with loom: directory not found: <path>. |
--port <n> | 5173 | Digits only, else exits 1 with loom: --port requires a numeric value. When absent, loom.config.ts can supply it. |
--host [addr] | false | Binds all interfaces. A following value that doesn’t start with - is used as the bind address. |
--targets [glob] | — | Switches to gallery mode. A following value that doesn’t start with - is the glob; otherwise **/*.loom.tsx. See glob semantics. |
Mode selection
The CLI picks a mode and passes it to loomPreview() as targets.
loomPreview({ targets }) in your own config
behaves the same.
-
--targetsis present, orloom.config.tssuppliestargets: gallery mode. The generated page mounts the targets. You need no client entry, and your ownindex.htmlis ignored. -
Otherwise, your project’s
index.htmlis used as-is. -
Otherwise, loom generates a page with a full-viewport
#loom-rootand loads the first entry that exists:src/main.client.tsxsrc/main.client.tssrc/client/main.client.tsxsrc/client/main.client.tssrc/main.tsxsrc/main.tssrc/index.tsxsrc/client.tsx -
If none exist, the CLI exits
1before starting the server, withloom: no index.html and no client entry found in <dir>and the list of candidates.
File-system access
server.fs.allow covers the project directory, the nearest ancestor with a pnpm-workspace.yaml,
and the installed @loom-dev/preview sources. A .git directory alone doesn’t count as a
workspace root.
loom build
Writes the gallery as a self-contained, client-only static site. It runs vite build with
loomPreview({ targets }) and configFile: false, so your own config with the same targets
emits the same output.
| Argument | Default | Rules |
|---|---|---|
dir | . | Positional, resolved against the working directory. |
--targets [glob] | required | Same parsing as preview. Absent: exits 1 with loom: `build` requires --targets [glob] (the static gallery is target-driven). |
--out <dir> | dist-preview | Resolved against the working directory, not dir. Emptied before writing. |
--base <path> | ./ | Vite’s public base path. The relative default works on any host. |
--no-assets | off | Skips downloading rbxassetid:// images, so the build stays off the network. Takes no value. See static builds. |
--out and --base need a value. Without one, the CLI exits 1 with loom: --out requires a value (or --base).
build does not read loom.config.ts. If the glob matches nothing, it exits non-zero with
no targets matched … — nothing to build.
On success it prints the output directory:
loom build → /Users/you/code/my-ui/dist-previewloom.config.ts
Read only by preview, from <dir>/loom.config.ts.
export default { targets: "src/scenes", // string | string[] port: 5204, // number shims: { "@rbxts/example": "./loom-shims/example.ts" }, // Record<string, string>};| Field | Type | Notes |
|---|---|---|
targets | string | string[] | A string or a non-empty array of strings. Turns on gallery mode. |
port | number | Used only when targets or shims is valid. |
shims | Record<string, string> | Non-empty strings only. See shims. |
- CLI flags always win over the file.
- A file with neither a valid
targetsnor a validshimsis skipped whole,portincluded, with a hint on stderr. - Node imports the file directly, using its built-in TypeScript support. An import failure prints a warning and the preview continues without the file.
Glob semantics
How --targets is normalized:
| Input | Pattern used |
|---|---|
| flag with no value | **/*.loom.tsx |
. or an empty string | **/*.loom.tsx |
a value containing * | used verbatim |
| any other value (a directory) | <value>/**/*.loom.tsx |
Leading ./ and trailing slashes are stripped first. The matcher knows three constructs: **/ (any
depth, including none), ** (anything) and * (anything but /). Every other character is literal.
Discovery walks the project recursively and skips node_modules and dot-entries. It returns sorted,
POSIX-style relative paths, and skips directories it can’t read.
Live target discovery
Under the dev server, adding or deleting a *.loom.tsx file triggers a full page reload, because
the sidebar is rebuilt. The URL hash survives the reload. Editing a target’s contents is ordinary
HMR.
loom-dev/embed — the programmatic API
Use loom-dev/embed when a host app already owns the dev server or the build output. It exposes the
same two pipelines as functions.
import { createGalleryServer, buildGallery } from "loom-dev/embed";
const gallery = await createGalleryServer({ root: "/path/to/my-ui", // project the targets live in targets: "src/scenes", // same semantics as --targets base: "/loom-preview/", // public path it answers under});
hostServer.middlewares.use(gallery.middleware);// …and on shutdown:await gallery.close();await buildGallery({ root: "/path/to/my-ui", targets: "src/scenes", outDir: "dist/loom-preview", // --out // base defaults to "./" — relative assets, hostable anywhere});| Export | What it does |
|---|---|
createGalleryServer(options) | Gallery Vite server in middleware mode. Resolves to { base, middleware, vite, close() }. |
buildGallery(options) | Static gallery build. Resolves to the output directory. |
findGalleryTargets(root, targets?) | The relative target paths that would be served. Useful for skipping cleanly when a checkout is absent. |
isGalleryRequest(url, base) | Whether a URL belongs to a gallery mounted at base. |
normalizeGalleryBase(base?) | Adds the leading and trailing slash Vite’s base expects. |
DEFAULT_GALLERY_BASE | "/loom-preview/" |
| Option | Applies to | Notes |
|---|---|---|
root | both | Project directory, resolved against the working directory. |
targets | both | Same semantics as --targets, or true for the default glob. |
base | both | /loom-preview/ for the server, ./ for a build. |
outDir | buildGallery | Like --out. |
shims | both | Package redirects, relative to root. See shims. |
assets | buildGallery | false skips the rbxassetid:// download, like --no-assets. |
hmrPort | createGalleryServer | The HMR WebSocket port. Unset, loom picks a free port per server. Pass a number to pin one, or false to run without HMR. |
Vite’s default HMR port, 24678, is usually taken by another Vite server. On a collision Vite logs it and the previews silently stop hot-reloading.
createGalleryServer runs its own Vite instance, and the host only forwards HTTP to it. That keeps
loom’s rewrite of react and @rbxts/* away from the host’s own React. HMR is the exception: its
WebSocket always gets a port of its own.
middleware answers only under base, and redirects the bare /loom-preview to the
trailing-slash form. It calls next() for everything else, so you can register it ahead of the
host’s own routes. Target discovery, the
URL contract and per-target error
containment all match the CLI.