Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change functionPerRoute to false by default #8546

Merged
merged 7 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/cool-pianos-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@astrojs/vercel': major
---

Turn off `functionPerRoute` by default

In the previous version of `@astrojs/vercel`, the default for `functionPerRoute` was changed to `true`. While this option has several advantages, if you're a free tier user you are likely to run into the limit of 12 functions per deployment. This will result in an error when you attempt to deploy.

For this reason, the `functionPerRoute` option is now back to defaulting to `false`. It's still a useful option if you have a paid plan and have previously run into issues with your single function exceeding the size limits.
8 changes: 5 additions & 3 deletions packages/integrations/vercel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,11 @@ export default defineConfig({

### Function bundling configuration

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.
The Vercel adapter combines all of your routes into a single function by default.

You can disable this and build to a single function by setting the `functionPerRoute` configuration option to `false`:
You also have the option to split builds into a separate function for each route using the `functionPerRoute` option. This reduces the size of each function, meaning you are less likely to exceed the size limit for an individual function. Also, code starts are faster.

Verify that your Vercel plan includes an appropriate number of functions before enabling `functionPerRoute`. For example, Vercel's free tier limits each deployment to no more than 12 functions. If your Vercel plan is insufficient for the number of routes in your project, you will receive an error message during deployment.

```js
// astro.config.mjs
Expand All @@ -250,7 +252,7 @@ import vercel from '@astrojs/vercel/serverless';
export default defineConfig({
output: 'server',
adapter: vercel({
functionPerRoute: false,
functionPerRoute: true,
}),
});
```
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/vercel/src/serverless/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default function vercelServerless({
imageService,
imagesConfig,
devImageService = 'sharp',
functionPerRoute = true,
functionPerRoute = false,
edgeMiddleware = false,
}: VercelServerlessConfig = {}): AstroIntegration {
let _config: AstroConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default defineConfig({
adapter: vercel({
// Pass some value to make sure it doesn't error out
includeFiles: ['included.js'],
functionPerRoute: true,
}),
output: 'server'
});
Loading