From 2e7ace321474cfb77546dcfdb94afaa762b56749 Mon Sep 17 00:00:00 2001 From: userquin Date: Sat, 10 Sep 2022 00:29:31 +0200 Subject: [PATCH] fix: handle properly adapter fallback --- src/config.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/config.ts b/src/config.ts index f54feb9..125fbe0 100644 --- a/src/config.ts +++ b/src/config.ts @@ -58,27 +58,32 @@ export function configureSvelteKitOptions( function createManifestTransform(base: string, options?: KitOptions): ManifestTransform { return async (entries) => { + const defaultAdapterFallback = 'prerendered/fallback.html' const suffix = options?.trailingSlash === 'always' ? '/' : '' let adapterFallback = options?.adapterFallback let excludeFallback = false // the fallback will be always generated by SvelteKit. // The adapter will copy the fallback only if it is provided in its options: we need to exclude it if (!adapterFallback) { - adapterFallback = 'prerendered/fallback.html' + adapterFallback = defaultAdapterFallback excludeFallback = true } - const manifest = entries.filter(({ url }) => !(excludeFallback && url === adapterFallback)).map((e) => { + // the fallback will be always in .svelte-kit/output/prerendered/fallback.html + const manifest = entries.filter(({ url }) => !(excludeFallback && url === defaultAdapterFallback)).map((e) => { let url = e.url // client assets in `.svelte-kit/output/client` folder. // SSG pages in `.svelte-kit/output/prerendered/pages` folder. // fallback page in `.svelte-kit/output/prerendered` folder (fallback.html is the default). - if (url.startsWith('client/')) + if (url.startsWith('client/')) { url = url.slice(7) - else if (url.startsWith('prerendered/pages/')) + } + else if (url.startsWith('prerendered/pages/')) { url = url.slice(18) - else if (url.startsWith('prerendered/')) - url = url.slice(12) + } + else if (url === defaultAdapterFallback) { + url = adapterFallback! + } if (url.endsWith('.html')) { if (url.startsWith('/'))