Configuration

Configuration

Configure x via x.config.ts at your project root. Use defineConfig from @thexjs/core for type-safe configuration.

defineConfig

All configuration options are optional. x provides sensible defaults so you can start with zero configuration and add settings as needed.

x.config.ts
import { defineConfig } from "@thexjs/core";export default defineConfig({  // Page routes  pagesDir: "src/pages",  // Layout directory (for root layouts)  layoutsDir: "src/layouts",  // API routes  apiDir: "src/api",  // Server functions  actionsDir: "src/actions",  // Content collections (markdown)  contentDir: "content",  // Dev server port  port: 3000,  // Legacy routes directory  routesDir: "src/routes",});

All options reference

options table
Option         Type       Default          DescriptionpagesDir       string     "src/pages"      File-based page routeslayoutsDir     string     "src/layouts"    Root layout directoryapiDir         string     "src/api"        File-based API routesactionsDir     string     "src/actions"    Server functionscontentDir     string     "content"        Markdown content collectionsport           number     3000             Dev server portroutesDir      string     undefined        Legacy routes directory

pagesDir

The directory containing your page route files. Defaults to src/pages. Each .tsx file becomes a route based on its file path.

layoutsDir

The directory for root layout components. Layouts wrap pages and can be nested using the _layout.tsx convention inside page directories.

apiDir

The directory for API route files. Files here respond to HTTP methods (GET, POST, etc.) and are served under /api/....

actionsDir

The directory for server functions. Exported async functions can be called from the browser via fetch('/__x/actions/...').

contentDir

The directory for markdown content collections. Files with frontmatter are scanned and can be loaded via scanContent and renderMarkdown.

port

The port number for the dev server. Defaults to 3000. Set to a different value if the default port is in use.

routesDir (legacy)

A legacy option for projects migrating from earlier versions of x. Maps to the same file-based routing convention. Prefer pagesDir for new projects.