Why Vercel?
Vercel is the platform created by the makers of Next.js, offering the best deployment experience:- Zero Configuration: Automatic detection of Next.js projects
- Instant Deployments: Deploy in seconds with git push
- Global CDN: Edge network for optimal performance
- Preview Deployments: Automatic preview URLs for pull requests
- Serverless Functions: Automatic API route handling
- Built-in Analytics: Performance monitoring included
Prerequisites
- GitHub, GitLab, or Bitbucket account
- Your Pengrafic project pushed to a git repository
- Vercel account (free tier available)
Deployment Steps
Create Vercel Account
Visit vercel.com and sign up with your git provider:
- Click “Sign Up”
- Choose GitHub, GitLab, or Bitbucket
- Authorize Vercel to access your repositories
Import Your Project
From your Vercel dashboard:
- Click “Add New…” → “Project”
- Select your git provider
- Find your Pengrafic repository
- Click “Import”
If you don’t see your repository, click “Adjust GitHub App Permissions” to grant access.
Configure Project
Vercel automatically detects Next.js projects. Verify the settings:Framework Preset: Next.js (auto-detected)Build & Development Settings:These values are read from your
package.json and should not need modification.Configure Environment Variables
Add your environment variables:
- Expand the “Environment Variables” section
- Add each variable with its key and value
You can add different values for Production, Preview, and Development environments.
Post-Deployment Configuration
Custom Domain
Add Domain
In your project settings:
- Go to “Settings” → “Domains”
- Click “Add”
- Enter your domain name (e.g.,
yourdomain.com) - Click “Add”
Configure DNS
Vercel will provide DNS records. Add them to your domain provider:For root domain (yourdomain.com):For www subdomain:
Environment Variables Management
Update environment variables after deployment:- Go to “Settings” → “Environment Variables”
- Click on a variable to edit or delete
- Click “Add” to create new variables
- Redeploy to apply changes (or they’ll apply on next deployment)
Changes to environment variables require a new deployment to take effect. Click “Redeploy” from the Deployments tab.
Automatic Deployments
Vercel automatically deploys your project:Production Deployments
- Triggered by pushes to your main/master branch
- Deployed to your production domain
- Runs full build and optimization
Preview Deployments
- Created for every pull request
- Unique preview URL for each PR
- Perfect for testing before merging
Vercel CLI (Optional)
Deploy directly from your terminal:Installation
Login
Deploy
Link Project
Link your local project to Vercel:Performance Optimization
Edge Functions
Vercel automatically deploys API routes as edge functions for optimal performance:- Global edge network
- Low latency worldwide
- Automatic scaling
Image Optimization
Next.js Image Optimization is automatically enabled:- On-demand image optimization
- Modern format conversion (WebP, AVIF)
- Automatic responsive images
Caching
Vercel provides intelligent caching:- Static assets cached at the edge
- Dynamic content with optimal cache headers
- Automatic cache invalidation on deployment
Monitoring and Analytics
Vercel Analytics
Enable built-in analytics:- Go to “Analytics” tab in your project
- Click “Enable Analytics”
- Install the package:
- Add to your root layout:
Real-time Logs
View logs in real-time:- Go to your project dashboard
- Click on a deployment
- View “Functions” tab for serverless function logs
- View “Build Logs” for build output
Troubleshooting
Build Fails
Check build logs:- Click on the failed deployment
- Review the build logs
- Fix errors in your code
- Push changes to trigger new deployment
- TypeScript errors: Run
npm run buildlocally first - Missing dependencies: Ensure
package.jsonis up to date - Environment variables: Check they’re set correctly
Runtime Errors
View function logs:- Go to your project dashboard
- Click “Functions” tab
- View real-time logs and errors
- Verify all required variables are set
- Ensure
NEXT_PUBLIC_prefix for client-side variables - Redeploy after updating variables
Image Issues
Configure image domains innext.config.js:
Performance Issues
Check Analytics:- Review Core Web Vitals scores
- Identify slow pages and functions
- Optimize based on data
Best Practices
Follow these best practices for optimal Vercel deployments:
- Use Environment Variables: Never commit secrets to git
- Test Locally: Run
npm run buildbefore pushing - Preview Deployments: Review preview URLs before merging
- Monitor Performance: Enable Vercel Analytics
- Optimize Images: Use
next/imagecomponent - Leverage Caching: Use appropriate cache headers
- Review Logs: Check function logs regularly
Additional Resources
Next Steps
Your Pengrafic application is now live on Vercel! Consider:- Setting up a custom domain
- Enabling Vercel Analytics
- Configuring preview deployments
- Adding monitoring and error tracking