Build & Compilation
Compile default-exported Brick applications into standalone Bun server bundles.
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():
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/brickOutput (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.jsRun the compiled server with Bun:
PORT=8080 bun dist/brick/server.jsOptions Table
| Flag | Argument | Default | Description |
|---|---|---|---|
<entry> | File path | (Required) | Application entry file. Must default-export a BrickApp instance. |
--outdir | Directory path | "dist/brick" | Target output directory for compiled bundles and IR artifacts. |
--port | Number | 4000 | Default listening port baked into the server launcher (overridable via PORT). |
--no-aot | Flag | false | Disables 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 routesProduction Readiness
The generated server.js includes:
- Production
PORTenvironment variable resolution with numeric validation (1-65535). - Graceful shutdown listeners for
SIGINTandSIGTERMsignals. - Ahead-of-time compiled Elysia route plans (when
--no-aotis not passed), reducing startup compilation work on cold boots.