diff --git a/.changeset/khaki-plants-compare.md b/.changeset/khaki-plants-compare.md new file mode 100644 index 000000000000..e98c38a8d627 --- /dev/null +++ b/.changeset/khaki-plants-compare.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/adapter-vercel': patch +--- + +Add prerendered routes to config diff --git a/packages/adapter-vercel/index.js b/packages/adapter-vercel/index.js index e938b5353be6..dada84e1384d 100644 --- a/packages/adapter-vercel/index.js +++ b/packages/adapter-vercel/index.js @@ -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'; @@ -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` }); @@ -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: {