Skip to content

Editable runtime config with HMR #14330

@pi0

Description

@pi0

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.


  1. Discussing with @Tahul, alongside with this feature, we might also introduce injected $appConfig for easier usage and access within templates.

  2. 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.config and $appConfig interface with theme subkey. But we can also introduce theme.config and useThemeConfig()/$themeConfig namespaced shortcuts from app config.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions