How It Works
Kiln operates in two phases: Build-Time Compilation and Runtime Initialization.
Phase 1: Build-Time Compilation
Section titled “Phase 1: Build-Time Compilation”When you run kiln:
Framework Build (next build / astro build) │ ▼1. Framework Auto-Detection • Discovers adapter (Next.js, Astro, etc.) │ ▼2. Asset Mapping & Dead-Code Pruning • Traverses standalone output & static assets • Prunes dead build artifacts (sourcemaps, dev bundles, Webpack machinery) • Compresses text server chunks >= 8KB with Level-1 Gzip │ ▼3. Standalone Entrypoint Generation • Generates assets.generated.js with embedded file imports • Generates server-entry.js with dynamic runtime loader hooks │ ▼4. Native Bun Compilation • Executes `bun build --compile --production --minify` • Emits single executable binaryPhase 2: Runtime Lifecycle
Section titled “Phase 2: Runtime Lifecycle”When the compiled binary is executed on a server:
- Cold Start (First Boot):
- Checks
.kiln-extractedfor a valid SHA-256 build stamp. - If not found or changed, unpacks embedded runtime assets into
baseDir(orKILN_RUNTIME_DIR). - Writes the new build stamp.
- Checks
- Warm Start (Subsequent Boots):
- Reads the build stamp and matches the embedded hash.
- Skips disk extraction completely and starts the HTTP server in 0ms.
- HTTP Server Execution:
- Delegates request handling to the framework’s native production engine (
startServerfor Next.js,entry.mjsfor Astro).
- Delegates request handling to the framework’s native production engine (
