# Loom
> Render a roblox-ts UI tree as a live web DOM preview, driven by Vite.
- Docs: https://docs.astra-void.xyz/loom/
- Source: https://github.com/astra-void/loom
# Loom
> Render a roblox-ts UI tree as a live web DOM preview, driven by Vite.
Source: https://docs.astra-void.xyz/loom/
Loom renders the `@rbxts/react` or `vide` UI you ship to Roblox in a browser. Layout follows
Roblox's rules, not CSS's: `UIListLayout`, `UIPadding`, `AutomaticSize`, `UISizeConstraint` and text
measurement run in a Rust layout engine compiled to WASM. Clicks, typing and hover reach your code
through `UserInputService` and instance signals, so a preview is interactive.
Run it on a roblox-ts project with no setup:
```bash
pnpm exec loom preview .
```
Or add one plugin to your own Vite config:
```ts title="vite.config.ts"
import { loomPreview } from "@loom-dev/preview/vite";
import { defineConfig } from "vite";
export default defineConfig({ plugins: [loomPreview()] });
```
The plugin generates the page, installs the Roblox globals (`UDim2`, `Color3`, `Enum`, `game`) and
the Luau standard library, and points `@rbxts/*` imports at browser versions. There is no
`rbxtsc` step: esbuild transpiles your TSX, and HMR works.
Start with [Installation](https://docs.astra-void.xyz/loom/getting-started/installation.md).
---
# Installation
> Install the loom CLI or the Vite plugin, and confirm a preview renders.
Source: https://docs.astra-void.xyz/loom/getting-started/installation/
Loom ships as two packages. Most projects need only one.
| How you want to run it | Install |
| --- | --- |
| The `loom preview` / `loom build` CLI, no Vite config of your own | `loom-dev` |
| `loomPreview()` in your own `vite.config.ts` | `@loom-dev/preview`, `react@18`, `vite` |
| Both | All of the above |
## Install the CLI
Start here if you're unsure. It is one dependency and needs no config file:
```bash
pnpm add -D loom-dev
```
`loom-dev` brings its own `@loom-dev/preview`, React and Vite.
## Install the plugin
To add the plugin to a Vite project you already have, install it with its peers:
```bash
pnpm add -D @loom-dev/preview react@^18.3.1 vite
```
The peers are `react ^18.3.1` and `vite ^6.0.0 || ^7.0.0`. Then follow
[Vite integration](https://docs.astra-void.xyz/loom/guides/vite-integration.md).
> **React 18 only**
>
> Loom's React adapter reads React 18 internals, so React 19 fails as soon as the preview loads. Pin
> `react@^18.3.1` and `@types/react@^18.3.12`.
## Verify
Run this in a roblox-ts project that has a client entry:
```bash title="Smoke test"
pnpm exec loom preview .
```
Open the printed URL, by default on port 5173. A dark page with your UI on it means everything is
working. A blank page usually means the entry doesn't mount itself; see
[Your first preview](https://docs.astra-void.xyz/loom/getting-started/first-preview.md#the-entry-must-mount-itself).
## What you don't install
- No roblox-ts build step. esbuild transpiles your TSX directly.
- No Rust toolchain. The layout engine ships prebuilt as a `.wasm` file inside `@loom-dev/layout`.
Both packages are ESM-only and MIT-licensed. Keep every `@loom-dev/*` package on the same version:
they release together, and mixed versions are not supported.
## Next step
Point loom at a project and get a preview on screen: [Your first
preview](https://docs.astra-void.xyz/loom/getting-started/first-preview.md).
---
# Your first preview
> Preview a roblox-ts project with the loom CLI and no config, or start one from scratch.
Source: https://docs.astra-void.xyz/loom/getting-started/first-preview/
Run the CLI and hand it a project directory:
```bash title="Preview a project"
pnpm exec loom preview ~/code/my-game
```
You don't add anything to the project: no `vite.config.ts`, no `index.html`, no entry changes. The
directory doesn't need its own `node_modules` either.
To get the same thing from your own Vite config, see [Vite integration](https://docs.astra-void.xyz/loom/guides/vite-integration.md).
## A complete project from scratch
No roblox-ts project yet? These three files are enough to render:
```text title="Project layout"
my-preview/
├── package.json
├── vite.config.ts
└── src/
└── main.client.tsx
```
```json title="package.json"
{
"name": "my-preview",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build"
},
"devDependencies": {
"@loom-dev/preview": "^0.13.2",
"react": "^18.3.1",
"vite": "^6.0.0"
}
}
```
```ts title="vite.config.ts"
import { loomPreview } from "@loom-dev/preview/vite";
import { defineConfig } from "vite";
export default defineConfig({ plugins: [loomPreview()] });
```
```tsx title="src/main.client.tsx"
import { useState } from "@rbxts/react";
import { createRoot } from "@rbxts/react-roblox";
function App() {
const [count, setCount] = useState(0);
return (
setCount((n) => n + 1) }}
>
);
}
createRoot().render();
```
```bash title="Run it"
pnpm install && pnpm vite
```
Open the printed URL. You get a rounded card with a label and a blue button, and the count goes up
when you click. Edits to `main.client.tsx` hot-reload.
You never import `UDim2`, `Color3`, `Enum` or `Vector2`. The plugin installs them as globals before
your entry runs.
> **Your editor will show type errors**
>
> The project renders, but your editor redlines `@rbxts/react`, `UDim2` and the lowercase elements.
> [TypeScript setup](https://docs.astra-void.xyz/loom/guides/typescript-setup.md) fixes that.
## What the plugin looks for
With no `index.html`, the plugin generates a page and loads the first entry it finds from this list:
```text title="Entry candidates, in priority order"
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
```
A normal roblox-ts project already matches one. If yours doesn't, name it with the plugin's `entry`
option. If the project has its own `index.html`, loom uses it, and its `