Watch Process
Watch Process
@dex/dev manages both the concurrent development workflow (dexDev) and the full production build pipeline (dexBuild).
Development Mode (dexDev)
When you run bun run dev (or dex start), dexDev({ rootDir, defineArgs? }):
- Resolves client-safe public environment variables (
PUBLIC_*,NEXT_PUBLIC_*,VITE_*) from.envandprocess.envviagetPublicEnvDefines(rootDir)ifdefineArgsis not provided. - Runs
bunx --bun dex-router generateonce to ensureroutes.ts,manifest.json, andlayouts.tsexist before the server boots. - Launches 4 concurrent processes via
spawnGroup:
| Process Name | Command | Purpose |
|---|---|---|
routes:watch | bunx --bun dex-router watch --pagesDir web/pages --layoutsDir web/layouts ... | Watches web/pages & web/layouts and regenerates route/layout manifests. |
styles:watch | bun tailwindcss -i web/styles/index.css -o web/public/assets/styles.css --watch | Recompiles Tailwind CSS on stylesheet or markup changes. |
client:watch | bun build core/bootstrap/web.tsx --target browser --splitting --format esm --outdir web/public/assets --entry-naming client.[ext] ... --watch | Bundles code-split ESM client code with public .env --define substitutions. |
server:dev | bun --watch core/runtime/app/index.ts | Runs and restarts the Elysia dev server on server code changes. |
spawnGroup Process Supervision
spawnGroup(tasks) prefixes stdout/stderr lines from each child with colorized tags (e.g. [routes:watch], [client:watch]). Set DEX_DEV_RAW=1 to inherit raw stdio without prefixes, or NO_COLOR=1 to disable ANSI colors. If any task exits with a non-zero code, or when SIGINT/SIGTERM is received, spawnGroup terminates all sibling processes cleanly.
Production Build Pipeline (dexBuild)
dexBuild({ rootDir, defineArgs? }) runs a 6-stage pipeline using dexPrepareBuild, dexPrerender, and dexBuildClient:
- Stage 1 — Route & layout generation
Runs
bunx --bun dex-router generateto writecore/router/.generated/routes.ts,core/router/.generated/manifest.json, andcore/router/.generated/layouts.ts. - Stage 2 — Build directory preparation (
dexPrepareBuild) Removes any previousbuild/directory, createsbuild/assets/, and copiesweb/public/index.htmltobuild/index.html. - Stage 3 — SSG prerendering (
dexPrerender) Inspectsdex.config.tsrenderStrategy(default'spa') and per-pagemetadata.renderStrategy. For every static route resolving to'ssg':- Wraps
GlobalLayout > NamedLayout > Pageinside<RouterContext.Provider value={createStaticRouterState(routePath, {})}>and renders HTML viareact-dom/serverrenderToString. - Injects rendered markup into
<div id="root">...</div>. - Injects page
<head>metadata (title,description, Open Graph, and Twitter card tags) and Google Fonts (cfg.fonts). - Writes each page to
build/__ssg/<route>/index.html(orbuild/__ssg/index.htmlfor/) and copies the prerendered tree tobuild/<route>/index.html.
- Wraps
- Stage 4 — Tailwind CSS compilation
Runs
bun tailwindcss -i web/styles/index.css -o build/assets/styles.css --minify. - Stage 5 — ESM code-split client bundling (
dexBuildClient) & SHA-256 cache busting Runsbun build core/bootstrap/web.tsx --target browser --splitting --format esm --minify --outdir build/assets --entry-naming client.[ext] --chunk-naming chunks/[name]-[hash].[ext](withdefineArgs). Then computes 8-character SHA-256 content hashes forbuild/assets/client.jsandbuild/assets/styles.cssand stamps?v=<hash>onto/assets/client.jsand/assets/styles.cssreferences across all HTML files underbuild/**/*.html(ensuring<script type="module">onclient.js). - Stage 6 — Standalone production server binary
Runs
bun build --compile core/runtime/server/prod.ts --outfile build/serverto produce a self-contained server executable.
Manual Regeneration
To regenerate routes and layouts outside of dexDev or dexBuild:
bunx --bun dex-router generateSee Also
- Dev Reload — How browser refresh works
- Dev vs Production — Mode differences
- Build Process — Build details