Loomreference

CLI

`loom preview` and `loom build` — every flag, its parsing rules, and config precedence.

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.

ArgumentDefaultRules
dir.Positional, resolved against the working directory. A missing directory exits 1 with loom: directory not found: <path>.
--port <n>5173Digits only, else exits 1 with loom: --port requires a numeric value. When absent, loom.config.ts can supply it.
--host [addr]falseBinds 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.

  1. --targets is present, or loom.config.ts supplies targets: gallery mode. The generated page mounts the targets. You need no client entry, and your own index.html is ignored.

  2. Otherwise, your project’s index.html is used as-is.

  3. Otherwise, loom generates a page with a full-viewport #loom-root and loads the first entry that exists:

    src/main.client.tsx
    src/main.client.ts
    src/client/main.client.tsx
    src/client/main.client.ts
    src/main.tsx
    src/main.ts
    src/index.tsx
    src/client.tsx
  4. If none exist, the CLI exits 1 before starting the server, with loom: 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.

ArgumentDefaultRules
dir.Positional, resolved against the working directory.
--targets [glob]requiredSame parsing as preview. Absent: exits 1 with loom: `build` requires --targets [glob] (the static gallery is target-driven).
--out <dir>dist-previewResolved against the working directory, not dir. Emptied before writing.
--base <path>./Vite’s public base path. The relative default works on any host.
--no-assetsoffSkips 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-preview

loom.config.ts

Read only by preview, from <dir>/loom.config.ts.

loom.config.ts
export default {
targets: "src/scenes", // string | string[]
port: 5204, // number
shims: { "@rbxts/example": "./loom-shims/example.ts" }, // Record<string, string>
};
FieldTypeNotes
targetsstring | string[]A string or a non-empty array of strings. Turns on gallery mode.
portnumberUsed only when targets or shims is valid.
shimsRecord<string, string>Non-empty strings only. See shims.
  • CLI flags always win over the file.
  • A file with neither a valid targets nor a valid shims is skipped whole, port included, 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:

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

Mount the gallery on a host dev server
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();
Emit the static gallery from a host build
await buildGallery({
root: "/path/to/my-ui",
targets: "src/scenes",
outDir: "dist/loom-preview", // --out
// base defaults to "./" — relative assets, hostable anywhere
});
ExportWhat 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/"
OptionApplies toNotes
rootbothProject directory, resolved against the working directory.
targetsbothSame semantics as --targets, or true for the default glob.
baseboth/loom-preview/ for the server, ./ for a build.
outDirbuildGalleryLike --out.
shimsbothPackage redirects, relative to root. See shims.
assetsbuildGalleryfalse skips the rbxassetid:// download, like --no-assets.
hmrPortcreateGalleryServerThe HMR WebSocket port. Unset, loom picks a free port per server. Pass a number to pin one, or false to run without HMR.

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.