mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(nuxt): load spaLoadingTemplate
if file exists (#23048)
This commit is contained in:
parent
40601ec15f
commit
28af761c74
@ -30,11 +30,6 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
|
||||
? [new RegExp(`node_modules\\/(?!${excludePaths.join('|')})`)]
|
||||
: [/node_modules/]
|
||||
|
||||
const spaLoadingTemplate = nuxt.options.spaLoadingTemplate ?? resolve(nuxt.options.srcDir, 'app/spa-loading-template.html')
|
||||
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}\`.`)
|
||||
}
|
||||
|
||||
const nitroConfig: NitroConfig = defu(_nitroConfig, {
|
||||
debug: nuxt.options.debug,
|
||||
rootDir: nuxt.options.rootDir,
|
||||
@ -86,15 +81,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
|
||||
baseURL: nuxt.options.app.baseURL,
|
||||
virtual: {
|
||||
'#internal/nuxt.config.mjs': () => nuxt.vfs['#build/nuxt.config'],
|
||||
'#spa-template': () => {
|
||||
if (!spaLoadingTemplate) { return 'export const template = ""' }
|
||||
try {
|
||||
if (spaLoadingTemplate !== true) {
|
||||
return `export const template = ${JSON.stringify(readFileSync(spaLoadingTemplate, 'utf-8'))}`
|
||||
}
|
||||
} catch {}
|
||||
return `export const template = ${JSON.stringify(defaultSpaLoadingTemplate({}))}`
|
||||
}
|
||||
'#spa-template': () => `export const template = ${JSON.stringify(spaLoadingTemplate(nuxt))}`
|
||||
},
|
||||
routeRules: {
|
||||
'/__nuxt_error': { cache: false }
|
||||
@ -415,3 +402,24 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
|
||||
function relativeWithDot (from: string, to: string) {
|
||||
return relative(from, to).replace(/^([^.])/, './$1') || '.'
|
||||
}
|
||||
|
||||
function spaLoadingTemplate (nuxt: Nuxt) {
|
||||
if (nuxt.options.spaLoadingTemplate === false) { return '' }
|
||||
|
||||
const spaLoadingTemplate = typeof nuxt.options.spaLoadingTemplate === 'string'
|
||||
? nuxt.options.spaLoadingTemplate
|
||||
: resolve(nuxt.options.srcDir, 'app/spa-loading-template.html')
|
||||
|
||||
try {
|
||||
if (existsSync(spaLoadingTemplate)) {
|
||||
return readFileSync(spaLoadingTemplate, 'utf-8')
|
||||
}
|
||||
} catch {}
|
||||
|
||||
if (nuxt.options.spaLoadingTemplate === true) {
|
||||
return defaultSpaLoadingTemplate({})
|
||||
}
|
||||
|
||||
console.warn(`[nuxt] Could not load custom \`spaLoadingTemplate\` path as it does not exist: \`${nuxt.options.spaLoadingTemplate}\`.`)
|
||||
return ''
|
||||
}
|
||||
|
@ -189,12 +189,11 @@ export default defineUntypedSchema({
|
||||
},
|
||||
|
||||
/**
|
||||
* A path to an HTML file, the contents of which will be inserted into any HTML page
|
||||
* Boolean or a path to an HTML file with the contents of which will be inserted into any HTML page
|
||||
* rendered with `ssr: false`.
|
||||
*
|
||||
* By default Nuxt will look in `~/app/spa-loading-template.html` for this file.
|
||||
*
|
||||
* You can set this to `false` to disable any loading indicator.
|
||||
* - If it is unset, it will use `~/app/spa-loading-template.html` if it exists.
|
||||
* - If it is false, no SPA loading indicator will be loaded.
|
||||
* - If true, Nuxt will look for `~/app/spa-loading-template.html` file or a default Nuxt image will be used.
|
||||
*
|
||||
* Some good sources for spinners are [SpinKit](https://github.com/tobiasahlin/SpinKit) or [SVG Spinners](https://icones.js.org/collection/svg-spinners).
|
||||
*
|
||||
@ -244,7 +243,7 @@ export default defineUntypedSchema({
|
||||
* @type {string | boolean}
|
||||
*/
|
||||
spaLoadingTemplate: {
|
||||
$resolve: async (val, get) => typeof val === 'string' ? resolve(await get('srcDir'), val) : (val ?? false)
|
||||
$resolve: async (val, get) => typeof val === 'string' ? resolve(await get('srcDir'), val) : val
|
||||
},
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user