Deploy to Vercel
Vercel is the recommended platform for deploying BlocksWeb applications. This guide covers everything you need to know to deploy your BlocksWeb site to Vercel.
Prerequisites
Before deploying, ensure you have:
- A BlocksWeb project ready for deployment
- A Vercel account
- Your project in a Git repository (GitHub, GitLab, or Bitbucket)
- BlocksWeb API credentials
Quick Deploy
The fastest way to deploy is using the Vercel CLI:
# Install Vercel CLI
npm i -g vercel
# Deploy from your project directory
vercelFollow the prompts to:
- Link to your Vercel account
- Configure project settings
- Set environment variables
- Deploy
Deploy via Git Integration
For automatic deployments on every push:
Step 1: Push to Git
Make sure your code is in a Git repository:
git init
git add .
git commit -m "Initial commit"
git remote add origin https://github.com/yourusername/your-repo.git
git push -u origin mainStep 2: Import to Vercel
- Go to https://vercel.com/new
- Click "Import Project"
- Select your Git provider (GitHub, GitLab, or Bitbucket)
- Find and import your repository
Step 3: Configure Project
Vercel will auto-detect Next.js. Verify these settings:
- Framework Preset: Next.js
- Build Command:
next build(default) - Output Directory:
.next(default) - Install Command:
npm install(or your preferred package manager)
Step 4: Add Environment Variables
Click "Environment Variables" and add:
BLOCKSWEB_API_KEY=your_api_key_here
BLOCKSWEB_WORKSPACE_ID=your_workspace_id_hereOptional variables:
# Custom API URL (if self-hosting)
BLOCKSWEB_API_URL=https://api.yoursite.com
# Feature flags
BLOCKSWEB_ENABLE_ANALYTICS=true
BLOCKSWEB_ENABLE_AB_TESTING=true
# Other Next.js environment variables
NEXT_PUBLIC_SITE_URL=https://yoursite.comStep 5: Deploy
Click "Deploy" and wait for the build to complete. Vercel will:
- Clone your repository
- Install dependencies
- Run the build command
- Deploy to production
Your site will be live at https://your-project.vercel.app.
Custom Domain
To add a custom domain:
1. Go to Project Settings
In your Vercel dashboard:
- Select your project
- Go to Settings → Domains
2. Add Domain
- Click "Add"
- Enter your domain (e.g.,
yoursite.com) - Click "Add"
3. Configure DNS
Vercel will provide DNS records. Add them to your domain registrar:
For root domain (yoursite.com):
- Type:
A - Name:
@ - Value:
76.76.21.21
For www subdomain:
- Type:
CNAME - Name:
www - Value:
cname.vercel-dns.com
DNS propagation can take up to 48 hours.
4. Verify
Once DNS propagates, Vercel will automatically provision an SSL certificate.
Environment-Specific Configuration
Production vs Preview
Use different API keys for production and preview deployments:
# Production (main branch)
BLOCKSWEB_API_KEY=bw_live_production_key
# Preview (all other branches)
BLOCKSWEB_API_KEY=bw_live_preview_keyIn Vercel, set environment variables with specific scopes:
- Production: Only
mainbranch - Preview: All other branches
- Development: Local development (not used on Vercel)
Branch-Specific Variables
For different staging environments:
- Go to Settings → Environment Variables
- Click "Add"
- Set "Environments": Select "Preview"
- Optional: Set "Git Branch": Specify branch name
Build Configuration
Custom Build Command
If you need custom build steps:
// package.json
{
"scripts": {
"build": "next build",
"build:production": "next build && node scripts/post-build.js",
"build:preview": "next build --no-lint"
}
}In Vercel settings, override the build command:
npm run build:productionBuild Output API
For advanced caching and optimization:
// next.config.js
module.exports = {
output: 'standalone', // Optimized Docker images
};Edge Runtime
To use Vercel Edge Runtime:
// app/[[...path]]/page.tsx
export const runtime = 'edge';
export default function Page() {
// Your page component
}Performance Optimization
Image Optimization
BlocksWeb images work automatically with Next.js Image Optimization:
import { Image } from '@blocksweb/core/client';
// Images are automatically optimized by Vercel
<Image
propName="heroImage"
asset={heroImage}
alt="Hero"
/>Caching Strategy
Configure caching headers:
// next.config.js
module.exports = {
async headers() {
return [
{
source: '/:path*',
headers: [
{
key: 'Cache-Control',
value: 's-maxage=60, stale-while-revalidate=3600',
},
],
},
];
},
};ISR (Incremental Static Regeneration)
For better performance, use ISR:
// app/[[...path]]/page.tsx
export const revalidate = 60; // Revalidate every 60 seconds
export default async function Page({ params }) {
// Fetch page data
return <Canvas path={path} />;
}Monitoring
Analytics
Enable Vercel Analytics:
npm install @vercel/analytics// app/layout.tsx
import { Analytics } from '@vercel/analytics/react';
export default function RootLayout({ children }) {
return (
<html>
<body>
{children}
<Analytics />
</body>
</html>
);
}Speed Insights
Enable Vercel Speed Insights:
npm install @vercel/speed-insights// app/layout.tsx
import { SpeedInsights } from '@vercel/speed-insights/next';
export default function RootLayout({ children }) {
return (
<html>
<body>
{children}
<SpeedInsights />
</body>
</html>
);
}Continuous Deployment
With Git integration enabled:
- Push to
main→ Automatic production deployment - Push to other branches → Automatic preview deployment
- Pull requests → Automatic preview URLs
Deployment Protection
Protect production deployments:
- Go to Settings → Git
- Enable "Production Branch" protection
- Require approvals before merging to
main
Preview Deployments
Every branch and PR gets a unique URL:
https://your-project-git-feature-branch-username.vercel.appShare this URL with stakeholders for review.
Troubleshooting
Build Fails
Check build logs:
- Go to Deployments
- Click on the failed deployment
- Review "Build Logs"
Common issues:
TypeScript errors:
# Fix: Run type check locally
npm run type-checkMissing environment variables:
# Fix: Add to Vercel dashboard under Environment VariablesOut of memory:
// next.config.js
module.exports = {
// Increase memory limit
experimental: {
largePageDataBytes: 128 * 1000,
},
};Environment Variables Not Working
Make sure:
- Variables are added in Vercel dashboard
- Correct environment scope (Production/Preview/Development)
- Redeploy after adding variables
Variables prefixed with NEXT_PUBLIC_ are exposed to the browser:
# Server-side only
BLOCKSWEB_API_KEY=secret
# Available in browser
NEXT_PUBLIC_SITE_URL=https://yoursite.com404 on Catch-All Routes
Ensure your catch-all route is configured correctly:
app/[[...path]]/page.tsx ✅ Correct
app/[...path]/page.tsx ❌ Won't match root `/`Slow Build Times
Optimize builds:
Use pnpm instead of npm:
json// package.json { "packageManager": "pnpm@8.0.0" }Enable caching:
javascript// next.config.js module.exports = { experimental: { turbotrace: true, }, };Reduce dependencies:
bashnpm prune --production
Advanced Configuration
Monorepo Support
For Turborepo or pnpm workspaces:
// vercel.json
{
"buildCommand": "cd ../.. && npx turbo run build --filter=website",
"outputDirectory": ".next",
"installCommand": "pnpm install"
}Custom Vercel Configuration
Create vercel.json:
{
"buildCommand": "npm run build",
"devCommand": "npm run dev",
"installCommand": "npm install",
"framework": "nextjs",
"regions": ["iad1", "sfo1"],
"headers": [
{
"source": "/(.*)",
"headers": [
{
"key": "X-Frame-Options",
"value": "DENY"
}
]
}
]
}Edge Config
For dynamic configuration:
import { get } from '@vercel/edge-config';
export default async function Page() {
const config = await get('feature-flags');
// Use config
}Cost Optimization
Vercel pricing is based on:
- Build minutes
- Serverless function invocations
- Bandwidth
- Edge middleware invocations
Optimize costs:
- Use ISR instead of SSR where possible
- Cache aggressively for static content
- Optimize images to reduce bandwidth
- Use Edge Runtime for better performance
Free tier includes:
- 100 GB bandwidth
- 100 hours build time
- 1000 serverless function invocations per day
Security
Secure Environment Variables
Never expose secrets in client-side code:
// ❌ BAD - Exposed to browser
const apiKey = process.env.NEXT_PUBLIC_BLOCKSWEB_API_KEY;
// ✅ GOOD - Server-side only
const apiKey = process.env.BLOCKSWEB_API_KEY;Security Headers
Add security headers in next.config.js:
module.exports = {
async headers() {
return [
{
source: '/:path*',
headers: [
{ key: 'X-DNS-Prefetch-Control', value: 'on' },
{ key: 'X-Frame-Options', value: 'SAMEORIGIN' },
{ key: 'X-Content-Type-Options', value: 'nosniff' },
{ key: 'Referrer-Policy', value: 'strict-origin-when-cross-origin' },
],
},
];
},
};Next Steps
- Quick Start - Get started with BlocksWeb
- Collections Overview - Add structured content
- Localization - Build multi-language sites