brust 2.0.0-alpha.66
Guide / CLI

CLI

Three commands: build compiles the app into dist/, start serves it, dev rebuilds and reloads while you edit.

The commands

brust --help
usage:
  brust build [entry=routes.tsx] [--out-dir dist] [--force] [--target bun|cloudflare|static] [--actions-only] [--strict] [--wasm-from-source] [--dev] [--update-tiers]
  brust dev [entry=routes.tsx] [--port N] [--workers N]    (Bun target: proxy + hot reload + inline TUI)
  brust dev [entry=routes.tsx] --target cloudflare [--out-dir dist] [--port N] [--wasm-from-source] [-- <wrangler args>]
  brust start [--port N] [--workers N] [--dist-dir dist] [--entry routes.tsx]
  brust shadcn init [component ...] [--force] [--css <file>] [--base-color <name>] [--shadcn-version <x.y.z>]

Exit codes: 0 on success, 1 for a build or boot error, 2 for a usage error.

What they print

Real output, from the pokedex example and from this site's own build.

Live demoSwitchPanels · native

The pokedex example. Each React fallback prints once, with its rule and line.

$ brust build routes.tsx
warning hook-unsupported components/TeamBuilder.tsx:12:3 hook useTransition is not supported
warning hook-unsupported components/UnifiedIsland.tsx:11:3 hook useTransition is not supported
[brust] built dist in 73ms

brust build

  • Takes one entry, routes.tsx by default. A build error prints error <rule> <message> and exits 1.
  • Writes to a temporary folder and swaps it in only on success.
  • dist/jinja/ holds one template per page and layout. A component placed inside a page is printed in that page’s template and gets no file of its own. Set BRUST_BUILD_ALL_TEMPLATES=1 to also write every component’s template when you want to read what one compiles to; the server ignores the extra files.
  • Compiles the pages and layouts on up to 4 compiler threads (fewer when the machine has fewer cores or the app fewer route files). Each thread keeps its own copy of the modules it reads, so a build takes more memory than on one thread. Set BRUST_COMPILE_THREADS to choose the number; BRUST_COMPILE_THREADS=1 compiles on one thread and gives that memory back. The output is the same at any number.
  • Refuses an out dir that is not empty and was not made by brust, unless you pass --force, and never writes to the app root, your home or a folder with sources (out-dir-unsafe).
  • --target cloudflare also writes dist/cf/, a Worker ready for wrangler.

The template of a page or layout in dist/jinja/ holds every component placed in it, and brust start parses each of them when it loads. When one is larger than 1 MB the build prints warning template <name> is <n> MB (<source>) and still succeeds: a template that large slows start-up and holds its memory. It usually comes from a component inlined at many call sites, a very large literal, or deep conditional nesting. A long chain of one operator (a && b && …, a || b || …, a ?? b ?? …) prints each operand a fixed number of times, so it does not cause it. Split the component, move the large data into a prop or a loader, or keep that component in React.

To fail the build instead of warning, set [build] template_max_bytes in brust.toml to the largest template you accept, in bytes (see Configuration). A build with a template over it stops with one template-size error that lists every such template, largest first, with its size and the file it came from; a template over the budget is reported by that error and not by the 1 MB warning. The budget applies to every template the build writes, so it also applies to the extra ones BRUST_BUILD_ALL_TEMPLATES=1 writes, which is a debugging aid. It works for every target. brust dev prints the same lines as warning template-size and keeps running. A build that fails publishes nothing: it is written beside the output directory and replaces it only when it has finished, so an existing dist/ stays as the last good build left it.

brust start

  • Serves the built dist/; it takes no entry argument. It sets NODE_ENV=production unless you set it.
  • SIGINT or SIGTERM drain in-flight requests, then exit 0. A second signal exits at once.
  • If a worker dies, the server drains and exits 1. It does not respawn workers: run it under a supervisor that restarts the process.

brust dev

brust dev is the development server for the Bun target. It rebuilds when you save, boots the new build beside the old one and swaps it in, and shows build errors above the last good page. It takes an entry, --port and --workers. The whole loop, the terminal keys, the browser overlay and the dev trace are on the Dev mode page.

brust dev --target cloudflare builds, runs wrangler dev, watches the app and rebuilds on a change (no hot reload). A failed rebuild keeps the running Worker. Arguments after -- go to wrangler, and the Bun dev server refuses them.

Every flag

FlagCommandsWhat it does
--out-dirbuild, dev (cloudflare)Where the build is written. Default dist.
--forcebuild, shadcn initbuild: writes into an out dir that is not empty and was not made by brust. shadcn init: replaces an existing components.json and runs the theme step again.
--target bun|cloudflare|staticbuild, devbun is the default. cloudflare also writes dist/cf/, a Worker for wrangler. static also renders every page to files in dist/static/ that you can upload to Cloudflare Pages (see Deployment).
--strictbuild --target staticA loader that reads the request (headers, cookies, query) fails the build instead of rendering the page a visitor with none of those would see.
--actions-onlybuildBuilds only the [actions] app, with no pages. It combines with --target bun (the default) and --target cloudflare. See Actions.
--devbuildAlso writes dev.json and builds the client runtime for dev. brust dev passes it for you; you rarely type it.
--update-tiersbuildRewrites the [tiers] snapshot with this build’s tiers instead of failing on a component that got heavier, and prints each difference. The [tiers.max] rules still apply. Without a [tiers] snapshot it prints tiers: --update-tiers has no effect: no [tiers] snapshot is configured and changes nothing. See Rendering tiers.
--wasm-from-sourcebuild, dev (cloudflare)Builds the Cloudflare wasm host from the repository's Rust source instead of using the published package.
--port, --workersstart, devThe port (0 picks a free one) and the number of Bun workers.
--dist-dir, --entrystartWhich built folder to serve and which routes module to load. Defaults dist and routes.tsx.
--css --base-color --shadcn-versionshadcn initThe Tailwind entry CSS (default: the one top-level app.css-style file that imports tailwindcss), the shadcn base colour (default neutral) and an exact shadcn CLI version (default: the one brust tests). See Set up shadcn/ui.
Note

A page-only build (pages that call actions on another origin) has no flag. It is what brust build does when brust.toml sets [actions] base_url and the project has no actions file.