fix(nuxt): enable hmr of app.config.ts files (#22494)

This commit is contained in:
Daniel Roe 2023-08-07 23:23:31 +01:00 committed by GitHub
parent 7dc7c80f74
commit 9c5b9b7d53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -280,10 +280,18 @@ export const appConfigTemplate: NuxtTemplate = {
write: true, write: true,
getContents: async ({ app, nuxt }) => { getContents: async ({ app, nuxt }) => {
return ` return `
import { updateAppConfig } from '#app'
import { defuFn } from '${await _resolveId('defu')}' import { defuFn } from '${await _resolveId('defu')}'
const inlineConfig = ${JSON.stringify(nuxt.options.appConfig, null, 2)} 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')} ${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(', ')}) export default /* #__PURE__ */ defuFn(${app.configs.map((_id: string, index: number) => `cfg${index}`).concat(['inlineConfig']).join(', ')})