Build Process
The Build Process
Dex's build pipeline transforms your source files into an ESM code-split client bundle, prerendered SSG HTML pages, minified Tailwind CSS, and a Standalone Bun server executable (build/server).
Development Mode
Run with the native Go CLI:
dex start(Or directly with Bun via bun run dev, which runs core/bootstrap/dev.ts.)
What happens:
- Runs
dex-router generateonce socore/router/.generated/is populated before starting watchers. - Spawns four concurrent processes via
@dex/dev:routes:watch: watchesweb/pages/andweb/layouts/and regeneratesroutes.ts,manifest.json, andlayouts.tsstyles:watch: compilesweb/styles/index.cssintoweb/public/assets/styles.csswith Tailwind CSS v4client:watch: runsbun build core/bootstrap/web.tsx --splitting --format esmintoweb/public/assets/server:dev: runsbun --watch core/runtime/app/index.tsonhttp://localhost:7990with/__dev/reloadSSE live reload
Production Build
Run with:
dex build(Or bun run build, which runs core/bootstrap/build.ts.)
What dexBuild() executes:
- Generate routes & layouts — scans
web/pages/andweb/layouts/to emitcore/router/.generated/routes.ts,manifest.json, andlayouts.ts - Prepare
build/— cleansbuild/, createsbuild/assets/, and copiesweb/public/index.htmltobuild/index.html - SSG prerender (
dexPrerender) — renders static routes whose strategy resolves to'ssg'with<RouterContext.Provider>(createStaticRouterState), injects<head>metadata (injectHeadMeta) and Google Fonts (injectGoogleFonts), and writes HTML tobuild/__ssg/<route>/index.htmlandbuild/<route>/index.html - Compile CSS — runs Tailwind CSS v4 (
bun tailwindcss -i web/styles/index.css -o build/assets/styles.css --minify) - Bundle client (ESM code splitting) — runs
bun build core/bootstrap/web.tsx --target browser --splitting --format esm --minify --outdir build/assets --entry-naming client.[ext] --chunk-naming chunks/[name]-[hash].[ext]withNEXT_PUBLIC_*,PUBLIC_*, andVITE_*defines - Cache-bust HTML assets — computes 8-char SHA-256 hashes of
build/assets/client.jsandbuild/assets/styles.cssand rewrites/assets/client.js?v=<hash>and/assets/styles.css?v=<hash>acrossbuild/index.htmland all prerendered HTML files - Compile server — compiles
core/runtime/server/prod.tswithbun build --compileinto a Standalone Bun server executable (build/server)
Output structure:
build/
├─ server # Standalone Bun server executable
├─ index.html # Entry HTML with ?v=<hash> asset URLs
├─ __ssg/ # Prerendered SSG HTML directory
│ ├─ index.html # Prerendered '/' (when SSG)
│ └─ about/index.html # Prerendered '/about' (when SSG)
├─ about/index.html # Copied static route HTML
└─ assets/
├─ client.js # Client router entry bundle
├─ chunks/
│ └─ [name]-[hash].js # Code-split page & layout chunks
└─ styles.css # Minified Tailwind CSSBuild & Run Commands
| Command | Purpose |
|---|---|
dex start | Start dev watchers and dev server (core/bootstrap/dev.ts) |
dex build | Run full production build (core/bootstrap/build.ts) |
dex start -p | Run compiled production binary (./build/server with NODE_ENV=production) |
bun run dev / build / start | Direct package.json script equivalents |
Generated Files
core/router/.generated/routes.ts
Maps sorted routes to lazy importPage loaders:
export const routes: Route[] = [
{
file: 'index.tsx',
path: '/',
segments: [],
importPage: () => import('../../../web/pages/index.tsx'),
},
{
file: 'about.tsx',
path: '/about',
segments: [{ kind: 'static', value: 'about' }],
importPage: () => import('../../../web/pages/about.tsx'),
},
]core/router/.generated/layouts.ts
Maps named layouts in web/layouts/ to lazy dynamic imports:
export const layouts: Record<string, () => Promise<LayoutModule>> = {
about: () => import('../../../web/layouts/about.tsx'),
global: () => import('../../../web/layouts/global.tsx'),
}Never edit these files — they are regenerated automatically.
Customization
Override output locations and rendering strategy in dex.config.ts:
export default {
renderStrategy: 'ssg',
pagesDir: 'src/pages',
layoutsDir: 'src/layouts',
outRoutesTs: 'src/.generated/routes.ts',
outRoutesJson: 'src/.generated/manifest.json',
outLayoutsTs: 'src/.generated/layouts.ts',
}See Also
- How Dex Works — Mental model
- Configuration — Customize paths, fonts, and subdomains
- Production Server — Running in production