@astrojs/vercel adapter enables your Astro project to deploy on Vercel with full SSR (Server-Side Rendering) and edge capabilities.
Installation
The adapter is already included in this boilerplate. To install it in a new project:Required Dependencies
Frompackage.json, the key dependencies are:
package.json
Basic Configuration
The adapter is configured inastro.config.mjs. Here’s the complete configuration from this boilerplate:
astro.config.mjs
Configuration Options
Output Mode
Set to
'server' to enable SSR (Server-Side Rendering) for your entire site.Individual pages can opt-in to static rendering by setting
export const prerender = true in the page frontmatter.Edge Middleware
Enables edge middleware support for running code on Vercel’s Edge Network.When enabled, your
src/middleware.ts file will run on the edge, allowing you to:- Intercept requests before they reach your pages
- Modify responses
- Add custom headers
- Implement authentication logic
Image Service
Enables Vercel’s Image Optimization service for automatic image processing.
Images Configuration
imagesConfig Options
imagesConfig Options
Array of image widths to generate. These should match your responsive breakpoints.
Allowed external domains for image optimization. Leave empty to allow all domains.
Fine-grained control over allowed remote image sources using pattern matching.
Use regex patterns for hostname and pathname to match specific URLs.
Web Analytics
Enables Vercel Web Analytics for tracking page views and performance metrics.
This requires Vercel Web Analytics to be enabled in your Vercel project settings.
Incremental Static Regeneration (ISR)
ISR Configuration Options
ISR Configuration Options
ISR allows you to update static pages without rebuilding your entire site.
Enable ISR with
true for default settings, or use an object for advanced configuration.Time in seconds before a page is regenerated. Default is 1 day (86400 seconds).
A secret token to bypass the cache and force regeneration.Use it in a URL like:
Routes that should always be served fresh (never cached).
Development vs Production
Development Image Service
Development Image Service
During development, you can use a different image service:This uses the lighter Squoosh service locally while Vercel’s optimization is used in production.
Example: Page with ISR
To use ISR on a specific page:src/pages/isr.astro
Vercel CLI Scripts
The boilerplate includes helpful Vercel CLI commands:package.json
- vercel:dev - Run the project locally with Vercel’s development environment
- vercel:link - Link your local project to a Vercel project
Install the Vercel CLI globally with
npm i -g vercel to use these commands.