Skip to content

Commit

Permalink
Add prerendered pages to routes config (#3822)
Browse files Browse the repository at this point in the history
* empty commit

* comment out redirect stuff

* try this

* add back redirects

* ugh vscode auto-import is the dumbest thing

* changeset
  • Loading branch information
Rich-Harris authored Feb 10, 2022
1 parent 8ba649a commit b05c9f1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/khaki-plants-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-vercel': patch
---

Add prerendered routes to config
22 changes: 20 additions & 2 deletions packages/adapter-vercel/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { writeFileSync } from 'fs';
import { existsSync, writeFileSync } from 'fs';
import { posix } from 'path';
import { fileURLToPath } from 'url';
import esbuild from 'esbuild';
Expand Down Expand Up @@ -102,7 +102,7 @@ export default function ({ external = [] } = {}) {

builder.log.minor('Prerendering static pages...');

await builder.prerender({
const prerendered = await builder.prerender({
dest: `${dir}/static`
});

Expand Down Expand Up @@ -143,10 +143,28 @@ export default function ({ external = [] } = {}) {
builder.log.minor('Writing routes...');

builder.mkdirp(`${dir}/config`);

const prerendered_routes = prerendered.paths
.map((path) => {
const file =
path === '/'
? '/index.html'
: path + (builder.trailingSlash === 'always' ? '/index.html' : '.html');

if (existsSync(`${dir}/static${file}`)) {
return {
src: path,
dest: file
};
}
})
.filter(Boolean);

writeFileSync(
`${dir}/config/routes.json`,
JSON.stringify([
...redirects[builder.trailingSlash],
...prerendered_routes,
{
src: `/${builder.appDir}/.+`,
headers: {
Expand Down

0 comments on commit b05c9f1

Please sign in to comment.