Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Nuxt 3.x reference covering SSR, file-based routing, auto-imports, server routes, and Nitro deployment.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/core-config.md
1---2name: configuration3description: Nuxt configuration files including nuxt.config.ts, app.config.ts, and runtime configuration4---56# Nuxt Configuration78Nuxt uses configuration files to customize application behavior. The main configuration options are `nuxt.config.ts` for build-time settings and `app.config.ts` for runtime settings.910## nuxt.config.ts1112The main configuration file at the root of your project:1314```ts15// nuxt.config.ts16export default defineNuxtConfig({17// Configuration options18devtools: { enabled: true },19modules: ['@nuxt/ui'],20})21```2223### Nuxt 4 Path Aliases2425In Nuxt 4 the default `srcDir` is `app/`, so the path aliases changed:2627| Alias | Resolves to |28|-------|-------------|29| `~` / `@` | `<rootDir>/app` |30| `~~` / `@@` | `<rootDir>` (project root) |31| `#shared` | `<rootDir>/shared` |32| `#server` | `<rootDir>/server` |3334Reference root-level paths (modules, server handlers) with `~~` or `#server`:3536```ts37export default defineNuxtConfig({38modules: ['~~/custom-modules/awesome.js'], // relative to rootDir39serverHandlers: [40{ route: '/foo/**', handler: '#server/foohandler.ts' },41],42})43```4445### Compatibility Version4647Nuxt 4 is the default behavior. To preview upcoming Nuxt 5 defaults (Vite Environment API, normalized page names, etc.):4849```ts50export default defineNuxtConfig({51future: {52compatibilityVersion: 5,53},54})55```5657### Environment Overrides5859Configure environment-specific settings:6061```ts62export default defineNuxtConfig({63$production: {64routeRules: {65'/**': { isr: true },66},67},68$development: {69// Development-specific config70},71$env: {72staging: {73// Staging environment config74},75},76})77```7879Use `--envName` flag to select environment: `nuxt build --envName staging`8081## Runtime Config8283For values that need to be overridden via environment variables:8485```ts86// nuxt.config.ts87export default defineNuxtConfig({88runtimeConfig: {89// Server-only keys90apiSecret: '123',91// Keys within public are exposed to client92public: {93apiBase: '/api',94},95},96})97```9899Override with environment variables:100101```ini102# .env103NUXT_API_SECRET=api_secret_token104NUXT_PUBLIC_API_BASE=https://api.example.com105```106107Access in components/composables:108109```vue110<script setup lang="ts">111const config = useRuntimeConfig()112// Server: config.apiSecret, config.public.apiBase113// Client: config.public.apiBase only114</script>115```116117## App Config118119For public tokens determined at build time (not overridable via env vars):120121```ts122// app/app.config.ts123export default defineAppConfig({124title: 'Hello Nuxt',125theme: {126dark: true,127colors: {128primary: '#ff0000',129},130},131})132```133134Access in components:135136```vue137<script setup lang="ts">138const appConfig = useAppConfig()139</script>140```141142## runtimeConfig vs app.config143144| Feature | runtimeConfig | app.config |145|---------|--------------|------------|146| Client-side | Hydrated | Bundled |147| Environment variables | Yes | No |148| Reactive | Yes | Yes |149| Hot module replacement | No | Yes |150| Non-primitive JS types | No | Yes |151152**Use runtimeConfig** for secrets and values that change per environment.153**Use app.config** for public tokens, theme settings, and non-sensitive config.154155## External Tool Configuration156157Nuxt uses `nuxt.config.ts` as single source of truth. Configure external tools within it:158159```ts160export default defineNuxtConfig({161// Nitro configuration162nitro: {163// nitro options164},165// Vite configuration166vite: {167// vite options168vue: {169// @vitejs/plugin-vue options170},171},172// PostCSS configuration173postcss: {174// postcss options175},176})177```178179### Environment-specific Vite Config180181Top-level `vite` options are shared. Use `$client` and `$server` to target a single Vite build:182183```ts184export default defineNuxtConfig({185vite: {186$client: {187build: { rollupOptions: { output: { manualChunks: { analytics: ['analytics-package'] } } } },188},189$server: {190build: { sourcemap: 'inline' },191},192},193})194```195196## Vue Configuration197198Enable Vue experimental features:199200```ts201export default defineNuxtConfig({202vue: {203propsDestructure: true,204},205})206```207208## Experimental Features & Defaults209210Notable Nuxt 4 flags under `experimental` (see source for the full list):211212```ts213export default defineNuxtConfig({214experimental: {215// Stream the HTML shell first, then render body progressively (better TTFB)216ssrStreaming: true,217// Run useFetch when its key changes even if immediate:false and not yet triggered218alwaysRunFetchOnKeyChange: true,219// Split useAsyncData handlers into separate chunks (static builds)220extractAsyncDataHandlers: true,221// pending is true before fetching starts222pendingWhenIdle: true,223// Default options for core composables/components224defaults: {225nuxtLink: { prefetch: true, prefetchOn: { visibility: true } },226useAsyncData: { deep: true },227useState: { resetOnClear: true },228},229},230})231```232233<!--234Source references:235- https://nuxt.com/docs/4.x/getting-started/configuration236- https://nuxt.com/docs/4.x/guide/going-further/runtime-config237- https://nuxt.com/docs/4.x/api/nuxt-config238- https://nuxt.com/docs/4.x/guide/going-further/experimental-features239-->240