brick.ts

Build & Compilation

Compile default-exported Brick applications into standalone Bun server bundles.

llms.txt

The brick build command compiles a default-exported BrickApp into a standalone Bun server bundle with ahead-of-time route handlers.

Minimal Example

Create an application entry that default-exports a brick() server instance without calling .listen():

src/server.ts
import { brick, defineService, t } from "@brickkit/core";

export const healthService = defineService("health");

healthService.action({
  name: "ping",
  method: "GET",
  output: t.Object({ ok: t.Boolean() }),
  execute: () => ({ ok: true }),
});

export const app = brick({
  services: [healthService],
  title: "Health API",
});

// Default export is required for brick build:
export default app;

Compile the application bundle:

brick build src/server.ts --outdir dist/brick

Output (paths printed are absolute, resolved from --outdir):

Compiled 1 services / 1 routes
IR: /Users/project/dist/brick/brick-ir.json
Run: bun /Users/project/dist/brick/server.js

Run the compiled server with Bun:

PORT=8080 bun dist/brick/server.js

Options Table

FlagArgumentDefaultDescription
<entry>File path(Required)Application entry file. Must default-export a BrickApp instance.
--outdirDirectory path"dist/brick"Target output directory for compiled bundles and IR artifacts.
--portNumber4000Default listening port baked into the server launcher (overridable via PORT).
--no-aotFlagfalseDisables ahead-of-time compilation of Elysia route handlers.

Application Configuration vs Build Flags: The flags --prefix and --no-request-logging are rejected. Passing either makes brick build throw; configure prefix and requestLogging directly in your brick({ prefix, requestLogging }) definition instead of CLI flags.

Output Bundle Structure

The compilation produces four artifacts in the output directory:

dist/brick/
├── server.js          # Standalone Bun server entry with graceful shutdown
├── routes.js          # Precompiled route dispatcher and IR bindings
├── server.js.map      # Source map for debugging
└── brick-ir.json      # Serialized intermediate representation of all routes

Production Readiness

The generated server.js includes:

  • Production PORT environment variable resolution with numeric validation (1-65535).
  • Graceful shutdown listeners for SIGINT and SIGTERM signals.
  • Ahead-of-time compiled Elysia route plans (when --no-aot is not passed), reducing startup compilation work on cold boots.