fix(nuxt): respect false to disable spa loading template (#21739)

This commit is contained in:
Daniel Roe 2023-06-25 17:38:31 +01:00 committed by GitHub
parent 88bc32d42a
commit 068ab19aab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,11 +31,9 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
? [new RegExp(`node_modules\\/(?!${excludePaths.join('|')})`)] ? [new RegExp(`node_modules\\/(?!${excludePaths.join('|')})`)]
: [/node_modules/] : [/node_modules/]
const spaLoadingTemplatePath = nuxt.options.spaLoadingTemplate ?? resolve(nuxt.options.srcDir, 'app/spa-loading-template.html') const spaLoadingTemplate = nuxt.options.spaLoadingTemplate ?? resolve(nuxt.options.srcDir, 'app/spa-loading-template.html')
if (spaLoadingTemplatePath !== false && !existsSync(spaLoadingTemplatePath)) { if (spaLoadingTemplate && nuxt.options.spaLoadingTemplate && !existsSync(spaLoadingTemplate)) {
if (nuxt.options.spaLoadingTemplate) { console.warn(`[nuxt] Could not load custom \`spaLoadingTemplate\` path as it does not exist: \`${spaLoadingTemplate}\`.`)
console.warn(`[nuxt] Could not load custom \`spaLoadingTemplate\` path as it does not exist: \`${spaLoadingTemplatePath}\`.`)
}
} }
const nitroConfig: NitroConfig = defu(_nitroConfig, { const nitroConfig: NitroConfig = defu(_nitroConfig, {
@ -87,10 +85,9 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
virtual: { virtual: {
'#internal/nuxt.config.mjs': () => nuxt.vfs['#build/nuxt.config'], '#internal/nuxt.config.mjs': () => nuxt.vfs['#build/nuxt.config'],
'#spa-template': () => { '#spa-template': () => {
if (!spaLoadingTemplate) { return 'export const template = ""' }
try { try {
if (spaLoadingTemplatePath) { return `export const template = ${JSON.stringify(readFileSync(spaLoadingTemplate, 'utf-8'))}`
return `export const template = ${JSON.stringify(readFileSync(spaLoadingTemplatePath, 'utf-8'))}`
}
} catch {} } catch {}
return `export const template = ${JSON.stringify(defaultSpaLoadingTemplate({}))}` return `export const template = ${JSON.stringify(defaultSpaLoadingTemplate({}))}`
} }