Configuration options
Rakkas looks for a configuration file named rakkas.config.js
(or .ts
) in your project root. This file is bundled with esbuild before loading, so you can use modern EcmaScript and TypeScript features.
The configuration file is not needed if you're happy with the defaults.
This file should default export a configuration object or a function that returns one (possibly asynchronously). Supported options are:
Property | Description | Default value |
---|---|---|
pageExtensions | File extensions for pages and layouts | ["jsx", "tsx"] |
pagesDir | Directory that contains pages and layouts relative to /src | "pages" |
endpointExtensions | File extensions for endpoints and middleware | ["js", "ts"] |
apiDir | Directory that contains API routes relative to /src | "api" |
apiRoot | Base URL for API routes | "/api" |
trustForwardedOrigin | Set to true to trust x-forwarded-* headers during development¹ | false |
prerender | An array of paths to be pre-rendered. | [] (["/"] for static) |
vite | Vite configuration (not all options are supported) | {} |
babel | Babel options passed to Vite's React plugin | {} |
modifyEsbuildOptions | Hook to modify ESBuild options used when bundling serverless functions | undefined |
locales.default | Default locale | "en" |
locales.detect | Set to true to enable locale detection | false |
locales.cookieName | Name of the locale override cookie | undefined |
¹ See the TRUST_FORWARDED_ORIGIN
environment variable for production use.
defineConfig
You can import the defineConfig
function from @rakkasjs/cli
to ensure TypeScript IDE completion.
Conditional configuration
You can provide a function (can be async) instead of a configuration object. The function will be called with the following info:
export interface ConfigFactoryInfo {
/** Rakkas command that is being executed */
command: "dev" | "build";
/** Deployment target (only available for the "build" command) */
deploymentTarget?:
| "node"
| "static"
| "vercel"
| "netlify"
| "cloudflare-workers";
}
You can also provide a function for Vite configuration. In build mode, it will be called with an argument specifying whether the configuration will be used for "ssr"
or "client"
.