Loomguides

Vite integration

`loomPreview()` in your own Vite project — dependencies, options, your own HTML entry, gallery mode.

Add loomPreview() to your own vite.config.ts and you get everything the loom CLI does: the generated page, client-entry detection and gallery mode. The CLI is just a Vite server with this one plugin.

1. Dependencies

package.json
{
"name": "my-game-ui",
"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"
}
}

React and Vite are peer dependencies of @loom-dev/preview, so you install them. Use React 18. The preview renderer doesn’t support other majors. See Installation.

2. The config

vite.config.ts
import { loomPreview } from "@loom-dev/preview/vite";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [loomPreview()],
});

That is the whole config, and you don’t need an index.html. vite and vite build now work on your roblox-ts source as-is.

  • The plugin adds its own esbuild, optimizeDeps, resolve.alias and server.fs.allow settings. Your own config is merged on top and wins.
  • With no index.html in the project root, the plugin generates one. It finds your client entry by checking the roblox-ts naming conventions, starting with src/main.client.tsx. See the full list.

See the plugin reference for exactly what it adds.

3. Options

Every option is optional. The defaults match the CLI.

vite.config.ts
loomPreview({
entry: "src/ui/boot.tsx", // only if your entry isn't a conventional name
targets: "src/scenes", // gallery mode: glob, directory, list, or true
title: "my-game-ui", // <title> of the generated page
html: false, // opt out of the generated page entirely
})
OptionTypeDefaultEffect
entrystringauto-detectedThe client entry, root-relative (/src/boot.tsx) or relative to the project root. Only needed when no conventional name fits.
targetsstring | string[] | true—Gallery mode. A glob, a directory (expanded to <dir>/**/*.loom.tsx), a list, or true for the default glob. Same as the CLI’s --targets. No client entry needed.
titlestring"loom preview" / "loom gallery"<title> of the generated page.
htmlbooleantruefalse turns off the generated page, entry detection and the Rollup input. Only the module setup stays.

shims and assets are covered in Package compatibility and Static builds.

4. Writing your own HTML entry

Your index.html needs an element with id="loom-root":

index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>my-game-ui preview</title>
<style>
html, body { margin: 0; height: 100%; background: #14161a; }
#loom-root { position: relative; width: 100vw; height: 100vh; overflow: hidden; }
</style>
</head>
<body>
<div id="loom-root"></div>
<script type="module" src="/src/main.client.tsx"></script>
</body>
</html>

This is the same page the plugin generates. Write your own when you want something extra in it, such as a font link, a wrapper element or a different background.

If #loom-root is missing, createRoot() adds one to <body>, but it is unstyled and won’t fill the viewport.

The entry is an ordinary roblox-ts client entry. See Your first preview. Run vite and you have an interactive preview: state updates, Activated handlers and text input all work.

5. vite build produces a static preview

Terminal window
pnpm vite build # → dist/

The build is a self-contained, client-only site: your entry, the renderer and the layout engine, hostable anywhere.

The plugin loads the Roblox globals (UDim2 and friends) before your entry, in the generated page and in your own index.html. You don’t need to import them yourself. If a built page still throws UDim2 is not defined, see Troubleshooting.

Pass targets to get the CLI’s *.loom.tsx gallery under vite. vite build then builds it as a static site you can deep-link into:

vite.config.ts
export default defineConfig({
plugins: [loomPreview({ targets: "src/scenes" })],
});

Each target becomes its own chunk. The built page follows the same URL contract as loom build, since it is the same build. See Gallery targets for how to write a target.

Next steps

Two things often break a working setup in a real workspace: importing the plugin by file path, and sharing a Vite config with an app that has its own React. Both are covered in Advanced Vite setup.

For error messages and what they mean, see Troubleshooting.