Nuxt/docs/content/1.docs/1.getting-started/3.configuration.md
Sébastien Chopin 90784f79d7
docs: new website design (#9007)
* docs: implement new website theme

* chore: rename dirs

* chore: update build

* lint fix

* chore: update deps

* fix: include node_modules in esbuild step

* chore: update deps

* Update .gitignore

* chore: update theme version

* up

* up

* fix: use svg for illustration

* chore: update to 0.0.12

* chore: force parse5 resolution

* stay with build

* feat: always display first home section

* Update yarn.lock

* chore: update theme

* fix lint

* docs: update home title

* chore: update website theme version

* Update docs/content/0.index.md

Co-authored-by: pooya parsa <pyapar@gmail.com>

* Update docs/content/0.index.md

Co-authored-by: pooya parsa <pyapar@gmail.com>

* up

* chore: bump theme version

* up

* chore: up

* up up and up

* chore: generate

* fix: boolean value

* feat: new images

* update again

* chore: up

* ouep

* chore: up

Co-authored-by: Daniel Roe <daniel@roe.dev>
Co-authored-by: Clément Ollivier <clement.o2p@gmail.com>
Co-authored-by: pooya parsa <pyapar@gmail.com>
2022-11-16 11:04:28 +01:00

4.2 KiB

navigation.icon description
uil:wrench Nuxt is configured with sensible defaults. The config file can override or extend them.

Configuration

By default, Nuxt is configured to cover most use cases. The nuxt.config.ts file can override or extend this default configuration.

Nuxt Configuration

The nuxt.config.ts file is located at the root of a Nuxt project and can override or extend the application's behavior.

A minimal configuration file exports the defineNuxtConfig function containing an object with your configuration. The defineNuxtConfig helper is globally available without import.

export default defineNuxtConfig({
  // My Nuxt config
})

This file will often be mentioned in the documentation, for example to add custom scripts, register modules or change rendering modes.

::alert{type=info} Every configuration option is described in the Configuration Reference. ::

::alert{type=info} You don't have to use TypeScript to build an application with Nuxt. However, it is strongly recommended to use the .ts extension for the nuxt.config file. This way you can benefit from hints in your IDE to avoid typos and mistakes while editing your configuration. ::

Environment Variables and Private Tokens

The runtimeConfig API exposes values like environment variables to the rest of your application. By default, these keys are only available server-side. The keys within runtimeConfig.public are also available client-side.

Those values should be defined in nuxt.config and can be overridden using environment variables.

::code-group

export default defineNuxtConfig({
  runtimeConfig: {
    // The private keys which are only available server-side
    apiSecret: '123',
    // Keys within public are also exposed client-side
    public: {
      apiBase: '/api'
    }
  }
})
# This will override the value of apiSecret
NUXT_API_SECRET=api_secret_token

::

These variables are exposed to the rest of your application using the useRuntimeConfig composable.

<script setup>
const runtimeConfig = useRuntimeConfig()
</script>

:ReadMore{link="/guide/going-further/runtime-config"}

App Configuration

The app.config.ts file, also located at the root of a Nuxt project, is used to expose public variables that can be determined at build time. Contrary to the runtimeConfig option, these can not be overriden using environment variables.

A minimal configuration file exports the defineAppConfig function containing an object with your configuration. The defineAppConfig helper is globally available without import.

export default defineAppConfig({
  title: 'Hello Nuxt',
  theme: {
    dark: true,
    colors: {
      primary: '#ff0000'
    }
  }
})

These variables are exposed to the rest of your application using the useAppConfig composable.

<script setup>
const appConfig = useAppConfig()
</script>

:ReadMore{link="/guide/directory-structure/app.config"}

runtimeConfig vs app.config

As stated above, runtimeConfig and app.config are both used to expose variables to the rest of your application. To determine whether you should use one or the other, here are some guidelines:

  • runtimeConfig: Private or public tokens that need to be specified after build using environment variables.
  • app.config : Public tokens that are determined at build time, website configuration such as theme variant, title and any project config that are not sensitive.
Feature runtimeConfig app.config
Client Side Hydrated Bundled
Environment Variables Yes No
Reactive Yes Yes
Types support Partial Yes
Configuration per Request No Yes
Hot Module Replacement No Yes
Non primitive JS types No Yes