diff --git a/.changeset/cool-pianos-smell.md b/.changeset/cool-pianos-smell.md new file mode 100644 index 000000000..6b222637a --- /dev/null +++ b/.changeset/cool-pianos-smell.md @@ -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. diff --git a/packages/integrations/vercel/README.md b/packages/integrations/vercel/README.md index 7776c2b30..7894cfeb3 100644 --- a/packages/integrations/vercel/README.md +++ b/packages/integrations/vercel/README.md @@ -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 @@ -275,7 +277,7 @@ import vercel from '@astrojs/vercel/serverless'; export default defineConfig({ output: 'server', adapter: vercel({ - functionPerRoute: false, + functionPerRoute: true, }), }); ``` diff --git a/packages/integrations/vercel/src/serverless/adapter.ts b/packages/integrations/vercel/src/serverless/adapter.ts index 12fb2caa7..88887fd3a 100644 --- a/packages/integrations/vercel/src/serverless/adapter.ts +++ b/packages/integrations/vercel/src/serverless/adapter.ts @@ -95,7 +95,7 @@ export default function vercelServerless({ imageService, imagesConfig, devImageService = 'sharp', - functionPerRoute = true, + functionPerRoute = false, edgeMiddleware = false, }: VercelServerlessConfig = {}): AstroIntegration { let _config: AstroConfig; diff --git a/packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes/astro.config.mjs b/packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes/astro.config.mjs index f5a86e609..da708f049 100644 --- a/packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes/astro.config.mjs +++ b/packages/integrations/vercel/test/fixtures/serverless-with-dynamic-routes/astro.config.mjs @@ -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' });