zerho Documentation
Everything you need to configure, run, benchmark, and extend zerho — the Zero-Node, 100% Rust frontend dev server and production bundler.
Quick Start
Create a new project using zerho init with either the basic-ts or react-tsx template:
# Scaffold a React + TypeScript project in milliseconds
zerho init my-app --template react-tsx
cd my-app
# Start the Zero-Node dev server (HMR + /@zerho/bundle + /__inspect)
zerho dev
# Audit the full module graph (broken imports, cycles, missing .env, secrets)
zerho check
# Build scope-hoisted, minified, Brotli-compressed bundle + dist/stats.html
zerho build --analyze
# Preview the production dist/ output locally (serves .br automatically)
zerho preview --port 4173 Once zerho dev is running, open http://127.0.0.1:5173/__inspect to inspect the live module graph, dependency edges, and blake3 disk cache hits.
zerho.toml Full Reference
All configuration is declarative and validated at startup by zerho-config. Run zerho schema to generate the official JSON Schema for editor tooling.
[project]
name = "my-app"
root = "."
entry = "src/main.tsx"
public_dir = "public"
env_prefix = "ZERHO_"
framework = "react" # react | preact | vanilla (solid uses classic JSX pragma)
[server]
host = "127.0.0.1"
port = 5173
hmr = true
open = false
partial_bundling = true # zero-waterfall /@zerho/bundle in dev
[server.proxy]
"/api" = "http://127.0.0.1:8080"
[build]
out_dir = "dist"
minify = true # oxc_minifier constant folding + DCE + mangling
sourcemap = "linked" # none | linked | inline | hidden
target = "es2022"
splitting = true # dynamic import() + shared chunks + modulepreload
brotli = true # emit .br pre-compressed assets
scope_hoisting = true # flatten acyclic ESM without runtime wrappers
analyze = false # emit dist/stats.html interactive treemap
ssr = false # emit DOM-free dist/server.mjs for Edge/SSR
# [build.entries] # Multi-Page App (MPA) script entry points
# index = "src/main.ts"
# admin = "src/admin.ts"
[build.budgets]
max_js_kb = 150
max_css_kb = 40
max_chunk_kb = 100
[css]
modules = true # native *.module.css via lightningcss
minify = true
[cache]
enabled = true
dir = ".zerho/cache" # embedded ACID redb B-tree cache
# remote_url = "http://127.0.0.1:9000/cache"
# remote_token = "env:ZERHO_CACHE_TOKEN"
[security]
sri = true # SHA-384 integrity in index.html & manifest.json
csp = true # emit strict dist/csp.json
secret_scan = true # fail build on leaked API keys / private keys
[assets]
optimize_svg = true # pure-Rust SVG minification
optimize_images = true # pure-Rust PNG/JPG -> WebP conversion
[plugins]
# wasm = ["plugins/my-plugin.wasm"] # sandboxed wasmtime plugins
# fuel_limit = 1000000
[build.lib]
# entry = "src/index.ts" # enables Library Mode (.mjs + .cjs)
# name = "my-lib"
# formats = ["es", "cjs"] CLI Commands
All commands ship inside the single 16.60 MB zerho binary.
| Command | Description |
|---|---|
| zerho init [DIR] --template <NAME> | Scaffold a Zero-Node project (basic-ts | react-tsx). |
| zerho migrate [DIR] [--dry-run] [--force] | Inspect package.json, vite.config.*, index.html, and tsconfig.json to generate a ready-to-run zerho.toml. |
| zerho dev [--config PATH] [--port PORT] | Start the axum + tokio dev server with WebSocket HMR, /@zerho/bundle, /@zerho/deps, and /__inspect UI. |
| zerho build [--config PATH] [--analyze] [--watch] [--ssr] | Parallel rayon build with Scope Hoisting, oxc_minifier, redb cache, Web Workers/.wasm, Shared Chunks + modulepreload, Brotli .br, SRI/CSP, SSR Edge mode, and optional dist/stats.html. |
| zerho check [--config PATH] [--strict] | Audit the full module graph in milliseconds for broken imports, circular dependencies, missing .env vars, and leaked secrets. |
| zerho preview [--config PATH] [--port PORT] | Serve the production dist/ directory locally with automatic Accept-Encoding: br negotiation. |
| zerho bench [--config PATH] [--iterations N] [--synthetic N] [--json] | Run reproducible cold Oxc transform, warm redb cache, and full/synthetic N-module build benchmarks with optional JSON telemetry. |
| zerho schema | Print the complete JSON Schema for zerho.toml for IDE validation and autocompletion. |
| zerho wit | Print the canonical zerho:plugin@0.1.0 WebAssembly Component Model WIT contract. |
Granular HMR & Shadow DOM Error Overlay
zerho-server injects the native /@zerho/client WebSocket runtime and walks reverse edges in zerho-graph to invalidate only affected modules. State persists across edits via import.meta.hot.data.
// Granular state-preserving HMR in any module
let count = import.meta.hot?.data.count ?? 0;
if (import.meta.hot) {
import.meta.hot.dispose((data) => {
data.count = count;
});
import.meta.hot.accept((nextMod) => {
// Hot-swap without losing component or module state
console.log('HMR updated:', nextMod);
});
} - Shadow DOM Isolation: Compile errors from oxc or lightningcss render inside <zerho-error-overlay> without leaking app CSS.
- Auto-Dismiss: Saving a valid fix clears the overlay automatically over WebSocket without a full page reload.
CSS Modules & Static Asset Imports
Files ending in .module.css are compiled by lightningcss into scoped class maps. Static assets (SVG, PNG, WebP, fonts) resolve via ?import in dev and emit blake3-hashed filenames in production builds.
// Scoped CSS Modules powered natively by lightningcss
import styles from './Button.module.css';
// Static asset imports (?import in dev, blake3-hashed emission in prod)
import logoUrl from './assets/logo.svg';
export function Header() {
return (
<header className={styles.bar}>
<img src={logoUrl} alt="zerho" width="32" height="32" />
</header>
);
} .env & [server.proxy]
Environment variables loaded from .env are strictly filtered by project.env_prefix (default: ZERHO_) before compile-time injection via DefinePlugin.
# .env (only keys matching project.env_prefix are exposed to client code)
ZERHO_API_URL=https://api.example.com
SECRET_DB_PASSWORD=never-exposed-to-browser
# In TypeScript:
const apiUrl = import.meta.env.ZERHO_API_URL;
const mode = import.meta.env.MODE; // "development" | "production" To forward API requests during local development without CORS friction, map path prefixes under [server.proxy] in zerho.toml (for example "/api" = "http://127.0.0.1:8080"). Static files placed in public/ are served at the root URL in dev and copied verbatim into dist/.
WASM Plugin WIT Contract (zerho:plugin@0.1.0)
Third-party plugins execute inside a fuel-metered wasmtime v29 sandbox (default fuel budget: 1,000,000 instructions) passing UTF-8 strings across linear memory (zerho_alloc, zerho_resolve_id, zerho_load, zerho_transform). See the complete Rust → .wasm reference plugin in examples/wasm-plugin/ or inspect this contract anytime via zerho wit:
package zerho:plugin@0.1.0;
interface types {
enum module-kind {
js,
ts,
jsx,
tsx,
css,
json,
asset,
virtual-mod,
}
record plugin-context {
is-dev: bool,
}
record transform-result {
code: string,
sourcemap: option<string>,
}
}
interface hooks {
use types.{module-kind, plugin-context, transform-result};
name: func() -> string;
resolve-id: func(specifier: string, importer: option<string>) -> result<option<string>, string>;
load: func(id: string, ctx: plugin-context) -> result<option<string>, string>;
transform: func(
code: string,
id: string,
kind: module-kind,
ctx: plugin-context,
) -> result<option<transform-result>, string>;
}
world zerho-plugin {
export hooks;
}