feat(nuxt): generate spa fallback for nuxt generate (#7507)

This commit is contained in:
pooya parsa 2022-09-14 17:16:24 +02:00 committed by GitHub
parent b8cb206dd0
commit 9ee5ca2b47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 10 deletions

View File

@ -58,7 +58,7 @@
"knitwork": "^0.1.2", "knitwork": "^0.1.2",
"magic-string": "^0.26.3", "magic-string": "^0.26.3",
"mlly": "^0.5.14", "mlly": "^0.5.14",
"nitropack": "^0.5.2", "nitropack": "^0.5.3",
"nuxi": "3.0.0-rc.9", "nuxi": "3.0.0-rc.9",
"ohash": "^0.1.5", "ohash": "^0.1.5",
"ohmyfetch": "^0.4.18", "ohmyfetch": "^0.4.18",

View File

@ -56,8 +56,8 @@ export async function initNitro (nuxt: Nuxt) {
prerender: { prerender: {
crawlLinks: nuxt.options._generate ? nuxt.options.generate.crawler : false, crawlLinks: nuxt.options._generate ? nuxt.options.generate.crawler : false,
routes: ([] as string[]) routes: ([] as string[])
.concat(nuxt.options._generate ? ['/', ...nuxt.options.generate.routes] : []) .concat(nuxt.options._generate ? ['/', '/200.html', ...nuxt.options.generate.routes] : [])
.concat(nuxt.options.ssr === false ? ['/', '/200.html', '/404.html'] : []) .concat(nuxt.options.ssr === false ? ['/index.html', '/200.html', '/404.html'] : [])
}, },
sourceMap: nuxt.options.sourcemap.server, sourceMap: nuxt.options.sourcemap.server,
externals: { externals: {

View File

@ -106,6 +106,8 @@ const getSPARenderer = lazyCachedFunction(async () => {
const PAYLOAD_CACHE = process.env.prerender ? new Map() : null // TODO: Use LRU cache const PAYLOAD_CACHE = process.env.prerender ? new Map() : null // TODO: Use LRU cache
const PAYLOAD_URL_RE = /\/_payload(\.[a-zA-Z0-9]+)?.js(\?.*)?$/ const PAYLOAD_URL_RE = /\/_payload(\.[a-zA-Z0-9]+)?.js(\?.*)?$/
const NO_SSR_ROUTES = new Set(['/index.html', '/200.html', '/404.html'])
export default defineRenderHandler(async (event) => { export default defineRenderHandler(async (event) => {
// Whether we're rendering an error page // Whether we're rendering an error page
const ssrError = event.req.url?.startsWith('/__nuxt_error') const ssrError = event.req.url?.startsWith('/__nuxt_error')
@ -130,7 +132,7 @@ export default defineRenderHandler(async (event) => {
req: event.req, req: event.req,
res: event.res, res: event.res,
runtimeConfig: useRuntimeConfig() as NuxtSSRContext['runtimeConfig'], runtimeConfig: useRuntimeConfig() as NuxtSSRContext['runtimeConfig'],
noSSR: !!event.req.headers['x-nuxt-no-ssr'], noSSR: !!(event.req.headers['x-nuxt-no-ssr']) || (process.env.prerender ? NO_SSR_ROUTES.has(url) : false),
error: !!ssrError, error: !!ssrError,
nuxt: undefined!, /* NuxtApp */ nuxt: undefined!, /* NuxtApp */
payload: (ssrError ? { error: ssrError } : {}) as NuxtSSRContext['payload'] payload: (ssrError ? { error: ssrError } : {}) as NuxtSSRContext['payload']

View File

@ -10227,9 +10227,9 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"nitropack@npm:^0.5.2": "nitropack@npm:^0.5.3":
version: 0.5.2 version: 0.5.3
resolution: "nitropack@npm:0.5.2" resolution: "nitropack@npm:0.5.3"
dependencies: dependencies:
"@cloudflare/kv-asset-handler": ^0.2.0 "@cloudflare/kv-asset-handler": ^0.2.0
"@netlify/functions": ^1.2.0 "@netlify/functions": ^1.2.0
@ -10243,7 +10243,7 @@ __metadata:
"@rollup/pluginutils": ^4.2.1 "@rollup/pluginutils": ^4.2.1
"@vercel/nft": ^0.22.1 "@vercel/nft": ^0.22.1
archiver: ^5.3.1 archiver: ^5.3.1
c12: ^0.2.11 c12: ^0.2.12
chalk: ^5.0.1 chalk: ^5.0.1
chokidar: ^3.5.3 chokidar: ^3.5.3
consola: ^2.15.3 consola: ^2.15.3
@ -10292,7 +10292,7 @@ __metadata:
bin: bin:
nitro: dist/cli.mjs nitro: dist/cli.mjs
nitropack: dist/cli.mjs nitropack: dist/cli.mjs
checksum: a27577af6902cbf606c56adcff0c2e88007c0eccfb31b674562fa36f88b91ddf02a2d490b08678aa6912e80ff8fc01502ff19cab4ba9cb488edf2223c89eee2f checksum: f43ce535feb213b2a7f8c06e44befdb4058e4c6e5f87c5923e35256ab5fee03c9e71d3d7a3b4aa6bc707b371a203f962447ca5a0b1c10b69d0e5466e7cf6e5ee
languageName: node languageName: node
linkType: hard linkType: hard
@ -10752,7 +10752,7 @@ __metadata:
knitwork: ^0.1.2 knitwork: ^0.1.2
magic-string: ^0.26.3 magic-string: ^0.26.3
mlly: ^0.5.14 mlly: ^0.5.14
nitropack: ^0.5.2 nitropack: ^0.5.3
nuxi: 3.0.0-rc.9 nuxi: 3.0.0-rc.9
ohash: ^0.1.5 ohash: ^0.1.5
ohmyfetch: ^0.4.18 ohmyfetch: ^0.4.18