-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[breaking] add builder.generateFallback(fallback) API (#8013)
closes #7899
- Loading branch information
1 parent
3d68052
commit 154ee74
Showing
6 changed files
with
102 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@sveltejs/adapter-static': patch | ||
'@sveltejs/kit': patch | ||
--- | ||
|
||
[breaking] replace automatic fallback generation with `builder.generateFallback(fallback)` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { readFileSync, writeFileSync } from 'fs'; | ||
import { dirname, join } from 'path'; | ||
import { pathToFileURL } from 'url'; | ||
import { mkdirp } from '../../utils/filesystem.js'; | ||
import { installPolyfills } from '../../exports/node/polyfills.js'; | ||
import { load_config } from '../config/index.js'; | ||
|
||
const [, , dest, manifest_path, env] = process.argv; | ||
|
||
/** @type {import('types').ValidatedKitConfig} */ | ||
const config = (await load_config()).kit; | ||
|
||
installPolyfills(); | ||
|
||
const server_root = join(config.outDir, 'output'); | ||
|
||
/** @type {import('types').ServerModule} */ | ||
const { Server, override } = await import(pathToFileURL(`${server_root}/server/index.js`).href); | ||
|
||
/** @type {import('types').SSRManifest} */ | ||
const manifest = (await import(pathToFileURL(manifest_path).href)).manifest; | ||
|
||
override({ | ||
building: true, | ||
paths: config.paths, | ||
read: (file) => readFileSync(join(config.files.assets, file)) | ||
}); | ||
|
||
const server = new Server(manifest); | ||
await server.init({ env: JSON.parse(env) }); | ||
|
||
const rendered = await server.respond(new Request(config.prerender.origin + '/[fallback]'), { | ||
getClientAddress: () => { | ||
throw new Error('Cannot read clientAddress during prerendering'); | ||
}, | ||
prerendering: { | ||
fallback: true, | ||
dependencies: new Map() | ||
} | ||
}); | ||
|
||
mkdirp(dirname(dest)); | ||
writeFileSync(dest, await rendered.text()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters