Dex

Configuration

Configuration

Dex works out of the box with sensible defaults. When you need to customize folder paths, rendering strategy, subdomains, Google fonts, dev watch targets, or @dex/pie OpenAPI codegen, configure dex.config.ts.

Default Structure

By default, Dex expects this layout:

my-app/
├─ web/
│  ├─ pages/           # Route components
│  ├─ layouts/         # Layout components
│  ├─ public/          # Static index.html & dev assets
│  └─ styles/          # Tailwind CSS entrypoint (index.css)
├─ routes/api/         # Elysia API routes
├─ lib/api.ts          # Userland @dex/pie client
└─ core/               # Bootstrap, runtime, and generated files

Custom Configuration

Create dex.config.ts (or .js, .mjs, .cjs, .json) in your project root:

import type { DexConfig } from '@dex/router'

export default {
  // Server & rendering
  mode: 'spa',
  port: 7990,
  renderStrategy: 'spa',

  // Router generation paths
  pagesDir: 'web/pages',
  layoutsDir: 'web/layouts',
  outRoutesTs: 'core/router/.generated/routes.ts',
  outRoutesJson: 'core/router/.generated/manifest.json',
  outLayoutsTs: 'core/router/.generated/layouts.ts',

  // Subdomain mounting
  subdomains: {
    docs: '/docs',
    admin: '/admin',
  },

  // Google Variable Fonts & Tailwind v4 @theme injection
  fonts: {
    sans: 'Inter',
    mono: {
      family: 'JetBrains Mono',
      variable: '--font-mono',
      weights: '400;500;700',
      display: 'swap',
    },
  },

  // @dex/pie OpenAPI codegen
  apiSpec: 'https://api.example.com/openapi.json',
  apiUrl: 'https://api.example.com',
  outApiTs: 'core/api/generated.ts',
  apiPrefix: '/api',

  // Extra watch targets for @dex/server dev reload
  watchFiles: [],
  watchDirs: [],
} satisfies DexConfig

Path Precedence

Dex resolves configuration in this order (highest to lowest priority):

  1. CLI flags — e.g. --pagesDir src/views or --out core/api/generated.ts
  2. Config file — dex.config.* values (resolved from the nearest parent directory)
  3. Built-in defaults — DEFAULT_PATHS (web/pages, web/layouts, core/api/generated.ts, /api, etc.)

All relative paths in dex.config.* are resolved relative to the directory containing the config file.

Available Options

OptionTypeDefaultDescription
modestring'spa'Application mode ('spa' or 'mpa')
portnumber7990Default dev and production server port
renderStrategy'spa' | 'ssg' | 'ssr' | 'ppr' | 'dynamic''spa'Default rendering strategy for routes ('ssg' enables build-time prerendering)
pagesDirstring'web/pages'Directory containing page route components (.tsx)
layoutsDirstring'web/layouts'Directory containing layout components (.tsx, .ts)
outRoutesTsstring'core/router/.generated/routes.ts'Target path for generated TypeScript route definitions
outRoutesJsonstring'core/router/.generated/manifest.json'Target path for generated route manifest JSON
outLayoutsTsstring'core/router/.generated/layouts.ts'Target path for generated layout loader map
subdomainsRecord<string, string>{}Map subdomain names to route path prefixes (e.g. { docs: '/docs' })
fontsDexFontsConfigundefinedGoogle Fonts / custom font specs injected into HTML <head> with CSS variables & .font-<key> classes
apiSpecstringundefinedOpenAPI JSON or YAML file path or URL used by dex pie generate
apiUrlstringundefinedDefault API base URL embedded into createApiClient()
outApiTsstring'core/api/generated.ts'Output path for @dex/pie generated TypeScript client
apiPrefixstring'/api'Path prefix stripped from generated @dex/pie route tree
watchFilesstring[][]Additional files watched by dexDevReloadRouter() for SSE live reload
watchDirsstring[][]Additional directories watched by dexDevReloadRouter() for SSE live reload

Subdomain Mounting (subdomains)

When subdomains is configured (for example { docs: '/docs' }), pass subdomains to <FileRouter /> and dexSpaFallback():

  • Visiting docs.example.com/getting-started transparently routes to /docs/getting-started while keeping /getting-started in the browser URL bar.
  • Visiting example.com/docs/getting-started issues a canonical 308 redirect on the server (or client redirect via resolveMainDomainSubdomainRedirect) to docs.example.com/getting-started.
  • Localhosts and IP addresses skip subdomain redirects so local development stays frictionless.

Fonts (fonts)

Each entry in fonts accepts either a font family string (which defaults to variable weights 100..900 from Google Fonts) or an object:

fonts: {
  sans: 'Plus Jakarta Sans',
  serif: {
    family: 'Newsreader',
    variable: '--font-serif',
    weights: '400;600',
    ital: true,
    display: 'swap',
    provider: 'google', // or 'none' for local/custom fonts
  },
}

During SSG prerendering (dexPrerender) and dynamic fallback responses (dexSpaFallback), @dex/dev and @dex/server inject Google Fonts <link> tags, :root CSS variables, and .font-<key> utility classes. @dex/server also exports generateFontThemeCss() to emit a Tailwind v4 @theme block.

CLI Overrides

Override config values on the command line:

# Override pages directory for router generation
bunx dex-router generate --pagesDir src/routes

# Override OpenAPI output and prefix for Pie
dex pie generate ./openapi.yaml --out lib/generated-api.ts --prefix /v1

Environment Variables

VariablePurpose
PORTDev/prod server port (overrides dex.config.ts port, default: 7990)
DEX_API_ONLYSet to 1 or true to serve only API routes in production
DEX_API_SPECFallback OpenAPI spec URL/path for dex pie generate
PUBLIC_API_URL / NEXT_PUBLIC_API_URLDefault API base URL for dex pie generate and client defines
NODE_ENVdevelopment or production

See Also

On this page