mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-18 06:31:27 +00:00
fix(nuxt): reload nitro when spa loading template updates (#24036)
This commit is contained in:
parent
c4bb8f31d4
commit
948b30d9c9
@ -1,6 +1,6 @@
|
|||||||
import { existsSync, promises as fsp, readFileSync } from 'node:fs'
|
import { existsSync, promises as fsp, readFileSync } from 'node:fs'
|
||||||
import { cpus } from 'node:os'
|
import { cpus } from 'node:os'
|
||||||
import { join, relative, resolve } from 'pathe'
|
import { join, normalize, relative, resolve } from 'pathe'
|
||||||
import { createRouter as createRadixRouter, exportMatcher, toRouteMatcher } from 'radix3'
|
import { createRouter as createRadixRouter, exportMatcher, toRouteMatcher } from 'radix3'
|
||||||
import { randomUUID } from 'uncrypto'
|
import { randomUUID } from 'uncrypto'
|
||||||
import { joinURL, withTrailingSlash } from 'ufo'
|
import { joinURL, withTrailingSlash } from 'ufo'
|
||||||
@ -366,6 +366,13 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
|
|||||||
// Init nitro
|
// Init nitro
|
||||||
const nitro = await createNitro(nitroConfig)
|
const nitro = await createNitro(nitroConfig)
|
||||||
|
|
||||||
|
// Trigger Nitro reload when SPA loading template changes
|
||||||
|
nuxt.hook('builder:watch', async (_event, path) => {
|
||||||
|
if (normalize(path) === spaLoadingTemplatePath(nuxt)) {
|
||||||
|
await nitro.hooks.callHook('rollup:reload')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// Set prerender-only options
|
// Set prerender-only options
|
||||||
nitro.options._config.storage ||= {}
|
nitro.options._config.storage ||= {}
|
||||||
nitro.options._config.storage['internal:nuxt:prerender'] = { driver: 'memory' }
|
nitro.options._config.storage['internal:nuxt:prerender'] = { driver: 'memory' }
|
||||||
@ -507,12 +514,16 @@ function relativeWithDot (from: string, to: string) {
|
|||||||
return relative(from, to).replace(/^([^.])/, './$1') || '.'
|
return relative(from, to).replace(/^([^.])/, './$1') || '.'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function spaLoadingTemplatePath (nuxt: Nuxt) {
|
||||||
|
return typeof nuxt.options.spaLoadingTemplate === 'string'
|
||||||
|
? resolve(nuxt.options.srcDir, nuxt.options.spaLoadingTemplate)
|
||||||
|
: resolve(nuxt.options.srcDir, 'app/spa-loading-template.html')
|
||||||
|
}
|
||||||
|
|
||||||
function spaLoadingTemplate (nuxt: Nuxt) {
|
function spaLoadingTemplate (nuxt: Nuxt) {
|
||||||
if (nuxt.options.spaLoadingTemplate === false) { return '' }
|
if (nuxt.options.spaLoadingTemplate === false) { return '' }
|
||||||
|
|
||||||
const spaLoadingTemplate = typeof nuxt.options.spaLoadingTemplate === 'string'
|
const spaLoadingTemplate = spaLoadingTemplatePath(nuxt)
|
||||||
? nuxt.options.spaLoadingTemplate
|
|
||||||
: resolve(nuxt.options.srcDir, 'app/spa-loading-template.html')
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (existsSync(spaLoadingTemplate)) {
|
if (existsSync(spaLoadingTemplate)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user