fix(nuxt): default spaLoadingTemplate to false (#22798)

This commit is contained in:
Daniel Roe 2023-08-25 13:26:23 +01:00 committed by GitHub
parent 54a6eab406
commit a352d59a58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 6 deletions

View File

@ -31,7 +31,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
: [/node_modules/] : [/node_modules/]
const spaLoadingTemplate = 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 (spaLoadingTemplate && nuxt.options.spaLoadingTemplate && !existsSync(spaLoadingTemplate)) { if (spaLoadingTemplate && nuxt.options.spaLoadingTemplate && typeof spaLoadingTemplate !== 'boolean' && !existsSync(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: \`${spaLoadingTemplate}\`.`)
} }
@ -89,7 +89,9 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
'#spa-template': () => { '#spa-template': () => {
if (!spaLoadingTemplate) { return 'export const template = ""' } if (!spaLoadingTemplate) { return 'export const template = ""' }
try { try {
if (spaLoadingTemplate !== true) {
return `export const template = ${JSON.stringify(readFileSync(spaLoadingTemplate, 'utf-8'))}` return `export const template = ${JSON.stringify(readFileSync(spaLoadingTemplate, 'utf-8'))}`
}
} catch {} } catch {}
return `export const template = ${JSON.stringify(defaultSpaLoadingTemplate({}))}` return `export const template = ${JSON.stringify(defaultSpaLoadingTemplate({}))}`
} }

View File

@ -241,10 +241,10 @@ export default defineUntypedSchema({
* } * }
* </style> * </style>
* ``` * ```
* @type {string | false} * @type {string | boolean}
*/ */
spaLoadingTemplate: { spaLoadingTemplate: {
$resolve: async (val, get) => typeof val === 'string' ? resolve(await get('srcDir'), val) : (val ?? null) $resolve: async (val, get) => typeof val === 'string' ? resolve(await get('srcDir'), val) : (val ?? false)
}, },
/** /**

View File

@ -32,7 +32,7 @@ describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM
const serverDir = join(rootDir, '.output/server') const serverDir = join(rootDir, '.output/server')
const serverStats = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir) const serverStats = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir)
expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot('"298k"') expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot('"297k"')
const modules = await analyzeSizes('node_modules/**/*', serverDir) const modules = await analyzeSizes('node_modules/**/*', serverDir)
expect.soft(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"1822k"') expect.soft(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"1822k"')
@ -71,7 +71,7 @@ describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM
const serverDir = join(rootDir, '.output-inline/server') const serverDir = join(rootDir, '.output-inline/server')
const serverStats = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir) const serverStats = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir)
expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot('"604k"') expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot('"603k"')
const modules = await analyzeSizes('node_modules/**/*', serverDir) const modules = await analyzeSizes('node_modules/**/*', serverDir)
expect.soft(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"70.5k"') expect.soft(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"70.5k"')