Nuxt/docs/content/1.docs/2.guide/2.directory-structure/3.app.config.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

1.8 KiB

navigation.icon title head.title description
IconFile app.config.ts Nuxt App Config Nuxt 3 provides the app.config file to expose reactive configuration within your application.

App Config File

Nuxt 3 provides an app.config config file to expose reactive configuration within your application with the ability to update it at runtime within lifecycle or using a nuxt plugin and editing it with HMR (hot-module-replacement).

You can easily provide runtime app configuration using app.config.ts file. It can have either of .ts, .js, or .mjs extensions.

export default defineAppConfig({
  foo: 'bar'
})

::alert{type=warning} Do not put any secret values inside app.config file. It is exposed to the user client bundle. ::

Defining App Config

To expose config and environment variables to the rest of your app, you will need to define configuration in app.config file.

Example:

export default defineAppConfig({
  theme: {
    primaryColor: '#ababab'
  }
})

When adding theme to the app.config, Nuxt uses Vite or webpack to bundle the code. We can universally access theme in both server and browser using useAppConfig composable.

const appConfig = useAppConfig()

console.log(appConfig.theme)

Manually Typing App Config

Nuxt tries to automatically generate a typescript interface from provided app config.

It is also possible to type app config manually:

declare module '@nuxt/schema' {
  interface AppConfigInput {
    /** Theme configuration */
    theme?: {
      /** Primary app color */
      primaryColor?: string
    }
  }
}

// It is always important to ensure you import/export something when augmenting a type
export {}