Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs] add runtimeConfig / appConfig explainer #14989

Closed
clemcode opened this issue Sep 20, 2022 — with Volta.net · 1 comment · Fixed by nuxt/framework#7689 or #18594
Closed

[Docs] add runtimeConfig / appConfig explainer #14989

clemcode opened this issue Sep 20, 2022 — with Volta.net · 1 comment · Fixed by nuxt/framework#7689 or #18594

Comments

Copy link
Contributor

At the moment, docs lack an explainer of the differences between the appConfig and runtimeConfig concepts, as they both allow to use environment variables.

https://v3.nuxtjs.org/guide/going-further/runtime-config
https://v3.nuxtjs.org/guide/directory-structure/app.config

@pi0
Copy link
Member

pi0 commented Sep 20, 2022

Here is a quick summary of their differences. Feel free to expand it and please mention if need any more info:

runtime config

It should be defined/declared from nuxt.config and can be overridden using environment variables in production runtime after build. It is accessible from server-only by default and only public namespace is added to the client payload and hydrated from SSR response. It cannot be overridden per request or dynamically after server is started but only initialized once. But is available both for server routes and app routes. It can contain only primitive JS values.

app config

It should be declared using app.config and can be overridden using nuxt plugins in both client and server environments and per request. Default values are bundled into the output both client-side and server-side so it is considered ppublic. It can also contain any JS variable.

When using

  • app.config: Public tokens that are determined on build time, website configuration such as theme variant, title and mostly any public project config that is determined on build time
  • runtime config: Private tokens or tokens that need to be specified after build using environment variables

Cons and pros

  • app.config: Is more efficient because is not in the bundle, it can have any js variable type and is better typed. But cannot be overridden using environment variables and hydrated.
  • runtime config: It is fully dynamic for a server-deployment that needs to change config after build. It can be hydrated but also adds to the page pageload and only accepts primitive js types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants