Skip to content

Commit

Permalink
Change functionPerRoute to false by default (#8546)
Browse files Browse the repository at this point in the history
* Change functionPerRoute to false by default

* Update test that depends on functionPerRoute

* Update .changeset/cool-pianos-smell.md

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>

* Update .changeset/cool-pianos-smell.md

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>

* Update packages/integrations/vercel/README.md

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>

* Update packages/integrations/vercel/README.md

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>

* Update .changeset/cool-pianos-smell.md

---------

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
  • Loading branch information
matthewp and sarah11918 committed Sep 14, 2023
1 parent 74dc3ed commit b79e11f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
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 @@ -263,9 +263,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 @@ -275,7 +277,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 @@ -95,7 +95,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'
});

0 comments on commit b79e11f

Please sign in to comment.