Skip to content

Commit

Permalink
fix: handle properly adapter fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
userquin committed Sep 9, 2022
1 parent 9d49ff5 commit 2e7ace3
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('/'))
Expand Down

0 comments on commit 2e7ace3

Please sign in to comment.