-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Editable runtime config with HMR #14330
Description
Currently, providing runtimeconfig from nuxt.config, .env and environment variables is possible but DX is not great because for each change, we need to restart Nuxt instance and there is no browser HMR.
We can introduce new app.config.[ext] (2) file that basically extends runtimeConfig.app namespace but is directly loaded by bundler (vite/webpack/nitro) and accepts hot module replacements and exposed as useAppConfig() / $appConfig (1). This file can also have more JS native types (non POJO).
import { defineAppConfig } from 'nuxt/app'
export default defineAppConfig ({
title: 'My Website',
seo: {
ogImage: '/og/card.png'
},
theme: {
primaryColor: '#ababab'
}
})Typing:
Same as RuntimeConfig, types can be inferred directly from config and extended from NuxtAppConfig interface from @nuxt/schema by modules and theme layers
HMR support:
Since the idea is to add a virtual template and dependency to the bundlers, HMR is expected to work out of the box. But we can make it even better to toggle reactivity for useRuntimeConfig() ref in app.
-
Discussing with @Tahul, alongside with this feature, we might also introduce injected
$appConfigfor easier usage and access within templates. -
Alongside with this feature, discussing with and by experience @nuxt/content-module team, there is a very common pattern to have a theme configuration. I personally vote for the simplicity of having one
app.configand$appConfiginterface withthemesubkey. But we can also introducetheme.configanduseThemeConfig()/$themeConfignamespaced shortcuts from app config.