Vercel adapter default changes (#8239)
* Vercel adapter default changes * Update .changeset/silly-dolphins-try.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Fix tests * chore: correctly export `pageModule` when using `functionPerRoute` * Update .changeset/silly-dolphins-try.md Co-authored-by: Emanuele Stoppa <my.burning@gmail.com> * Update .changeset/silly-dolphins-try.md Co-authored-by: Emanuele Stoppa <my.burning@gmail.com> * Make throw be the entrypoint --------- Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
This commit is contained in:
parent
ffc9e2d3de
commit
52f0837bde
8 changed files with 39 additions and 8 deletions
9
.changeset/silly-dolphins-try.md
Normal file
9
.changeset/silly-dolphins-try.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
'@astrojs/vercel': major
|
||||
---
|
||||
|
||||
Vercel adapter now defaults to `functionPerRoute`.
|
||||
|
||||
With this change, `@astrojs/vercel/serverless` now splits each route into its own function. By doing this, the size of each function is reduced and startup time is faster.
|
||||
|
||||
You can disable this option, which will cause the code to be bundled into a single function, by setting `functionPerRoute` to `false`.
|
|
@ -163,7 +163,7 @@ export async function generatePages(opts: StaticBuildOptions, internals: BuildIn
|
|||
opts.settings.adapter?.adapterFeatures?.functionPerRoute
|
||||
) {
|
||||
// forcing to use undefined, so we fail in an expected way if the module is not even there.
|
||||
const ssrEntry = ssrEntryPage?.manifest?.pageModule;
|
||||
const ssrEntry = ssrEntryPage?.pageModule;
|
||||
if (ssrEntry) {
|
||||
await generatePage(pageData, ssrEntry, builtPaths, pipeline);
|
||||
} else {
|
||||
|
|
|
@ -178,6 +178,8 @@ function vitePluginSSRSplit(
|
|||
imports.push(...ssrCode.imports);
|
||||
contents.push(...ssrCode.contents);
|
||||
|
||||
exports.push('export { pageModule }');
|
||||
|
||||
return `${imports.join('\n')}${contents.join('\n')}${exports.join('\n')}`;
|
||||
}
|
||||
return void 0;
|
||||
|
|
|
@ -210,9 +210,11 @@ export default defineConfig({
|
|||
});
|
||||
```
|
||||
|
||||
### Per-page functions
|
||||
### Function bundling configuration
|
||||
|
||||
The Vercel adapter builds to a single function by default. Astro 2.7 added support for splitting your build into separate entry points per page. If you use this configuration the Vercel adapter will generate a separate function for each page. This can help reduce the size of each function so they are only bundling code used on that page.
|
||||
The Vercel adapter splits builds into a separate function per route by default. This helps reduce the size of each function, as it only bundles code used on that page.
|
||||
|
||||
You can disable this and build to a single function by setting the `functionPerRoute` configuration option to `false`:
|
||||
|
||||
```js
|
||||
// astro.config.mjs
|
||||
|
@ -222,7 +224,7 @@ import vercel from '@astrojs/vercel/serverless';
|
|||
export default defineConfig({
|
||||
output: 'server',
|
||||
adapter: vercel({
|
||||
functionPerRoute: true,
|
||||
functionPerRoute: false,
|
||||
}),
|
||||
});
|
||||
```
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
"bugs": "https://github.com/withastro/astro/issues",
|
||||
"homepage": "https://docs.astro.build/en/guides/integrations-guide/vercel/",
|
||||
"exports": {
|
||||
"./edge": "./dist/edge/adapter.js",
|
||||
"./edge/entrypoint": "./dist/edge/entrypoint.js",
|
||||
"./edge": "./dist/edge/throw.js",
|
||||
"./edge/entrypoint": "./dist/edge/throw.js",
|
||||
"./serverless": "./dist/serverless/adapter.js",
|
||||
"./serverless/entrypoint": "./dist/serverless/entrypoint.js",
|
||||
"./static": "./dist/static/adapter.js",
|
||||
|
|
18
packages/integrations/vercel/src/edge/throw.ts
Normal file
18
packages/integrations/vercel/src/edge/throw.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
const msg = `
|
||||
The Astro Vercel Edge adapter has been removed. We recommend switching to @astrojs/vercel/serverless and enabling Edge middleware.
|
||||
|
||||
import { defineConfig } from 'astro/config';
|
||||
import vercel from '@astrojs/vercel/serverless';
|
||||
|
||||
export default defineConfig({
|
||||
output: 'server',
|
||||
adapter: vercel({
|
||||
edgeMiddleware: true,
|
||||
})
|
||||
})
|
||||
`.trim();
|
||||
|
||||
throw new Error(msg);
|
||||
|
||||
// Make sure bundlers treat this as ESM.
|
||||
export default {};
|
|
@ -68,7 +68,7 @@ export default function vercelServerless({
|
|||
analytics,
|
||||
imageService,
|
||||
imagesConfig,
|
||||
functionPerRoute = false,
|
||||
functionPerRoute = true,
|
||||
edgeMiddleware = false,
|
||||
}: VercelServerlessConfig = {}): AstroIntegration {
|
||||
let _config: AstroConfig;
|
||||
|
|
|
@ -4,7 +4,7 @@ import vercel from '@astrojs/vercel/serverless';
|
|||
export default defineConfig({
|
||||
adapter: vercel({
|
||||
// Pass some value to make sure it doesn't error out
|
||||
includeFiles: ['included.js']
|
||||
includeFiles: ['included.js'],
|
||||
}),
|
||||
output: 'server'
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue