From 9c5b9b7d536e6d2aca83690c5f4fcd35cc52d553 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 7 Aug 2023 23:23:31 +0100 Subject: [PATCH] fix(nuxt): enable hmr of `app.config.ts` files (#22494) --- packages/nuxt/src/core/templates.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/nuxt/src/core/templates.ts b/packages/nuxt/src/core/templates.ts index ba16996317..380d7d0cbf 100644 --- a/packages/nuxt/src/core/templates.ts +++ b/packages/nuxt/src/core/templates.ts @@ -280,10 +280,18 @@ export const appConfigTemplate: NuxtTemplate = { write: true, getContents: async ({ app, nuxt }) => { return ` +import { updateAppConfig } from '#app' import { defuFn } from '${await _resolveId('defu')}' const inlineConfig = ${JSON.stringify(nuxt.options.appConfig, null, 2)} +// Vite - webpack is handled directly in #app/config +if (import.meta.hot) { + import.meta.hot.accept((newModule) => { + updateAppConfig(newModule.default) + }) +} + ${app.configs.map((id: string, index: number) => `import ${`cfg${index}`} from ${JSON.stringify(id)}`).join('\n')} export default /* #__PURE__ */ defuFn(${app.configs.map((_id: string, index: number) => `cfg${index}`).concat(['inlineConfig']).join(', ')})