☀️Siang
DevOps & Cloud

Vercel: Frontend Cloud Platform

GRATIS

Panduan lengkap Vercel — deploy Next.js, serverless functions, edge functions, preview deployments, environment variables, domain management, dan best practices untuk frontend deployment

Artikel: Vercel Deployment Artikel: Vercel Deployment

1. Pengenalan Vercel

Vercel adalah cloud platform yang dirancang khusus untuk frontend developer. Didirikan oleh Guillermo Rauch (pembuat Socket.io dan Mongoose), Vercel adalah perusahaan di balik Next.js — framework React paling populer saat ini. Platform ini menyediakan infrastruktur yang dioptimalkan untuk frontend, memungkinkan developer untuk deploy dengan mudah dan cepat.

Vercel menawarkan pendekatan Git-centric deployment — setiap push ke repository secara otomatis menghasilkan deployment baru. Tidak perlu mengkonfigurasi CI/CD pipeline, Docker, atau server. Cukup hubungkan repository, dan Vercel menangani sisanya.

Mengapa Vercel Populer?

Keunggulan Penjelasan
Zero-Config DeployAuto-detect framework, build, dan deploy tanpa konfigurasi
Preview DeploymentsSetiap PR mendapatkan URL preview untuk review
Edge NetworkGlobal CDN — konten disajikan dari edge terdekat ke user
Serverless FunctionsBackend API tanpa mengelola server
Edge FunctionsCode yang berjalan di edge — latency sangat rendah
Next.js OptimalFirst-class support untuk Next.js — ISR, SSR, SSG, App Router
Free TierHobby plan gratis untuk personal project — cukup generous
DX TerbaikDeveloper experience yang sangat baik — logs, analytics, speed insights
Diagram: Vercel Architecture
Vercel Architecture

Users (Global)

EDGE NETWORK (CDN) EU Edge

US Edge cache + route

cache + route

APAC Edge cache + route

RUNTIME

Static Assets ISR / SSG

Serverless Fn Node / Edge Functions

Database PlanetScale

CMS Contentful

Custom APIs REST / GraphQL

💡 Tips

Vercel bukan hanya untuk Next.js — mendukung React, Vue, Svelte, Astro, Nuxt, Remix, Gatsby, dan banyak lagi. Namun integrasi terbaik memang dengan Next.js karena Vercel adalah pengembangnya.

2. Memulai dengan Vercel

Instalasi Vercel CLI

Diagram: Preview Deployments Flow
Preview Deployments Flow

Developer git push

GitHub Pull Request

Vercel Preview Deploy (auto URL)

Preview URL my-app-abc123.vercel.app unique per...

Auto Features Auto comment di PR Lighthouse sco...

Team Member Review dan Approve

Merge to main production deploy

Web Analytics preview Comment otomatis dengan U...

Branch Aliases feature/login staging.myapp.com ...

Branch Alias

Bash
# Preview deployments mendapatkan URL random
# Contoh: my-app-git-feature-login-username.vercel.app

# Set branch alias untuk URL yang lebih mudah diingat
# Di Vercel Dashboard > Project > Settings > Domains
# atau dengan CLI:
vercel alias set my-app-git-feature-login-username.vercel.app staging.myapp.com

# Set branch-level alias otomatis di vercel.json
{
  "git": {
    "deploymentEnabled": {
      "main": true,
      "develop": true,
      "feature/*": true
    }
  }
}
💡 Tips

Aktifkan "Protect Preview Deployments" di settings untuk membatasi akses preview hanya ke tim Anda. Ini penting jika preview mengandung data sensitif atau belum siap untuk publik.

7. Environment Variables

Environment variables di Vercel digunakan untuk menyimpan konfigurasi yang berbeda per environment (development, preview, production). Vercel mendukung beberapa jenis variable yang bisa diakses di build time atau runtime.

Jenis Environment Variables

Jenis Penggunaan
NEXT_PUBLIC_*Exposed ke client browser (build-time)
Server-onlyHanya tersedia di server/API routes (runtime)
EncryptedTer-enkripsi di Vercel, tidak bisa dilihat lagi
Bash
# Set environment variable via CLI
vercel env add DATABASE_URL
# Pilih environment: Production, Preview, Development

# Set untuk semua environment sekaligus
vercel env add API_SECRET production preview development

# List semua environment variables
vercel env ls

# Pull environment variables ke .env.local
vercel env pull .env.local

# Hapus environment variable
vercel env rm DATABASE_URL
⚠️ Peringatan

Jangan pernah commit .env.local ke Git! Pastikan .env.local ada di .gitignore. Gunakan Vercel Dashboard atau CLI untuk mengelola environment variables di production.

8. Custom Domains

Vercel mendukung custom domains dengan SSL otomatis. Setiap project mendapatkan .vercel.app subdomain gratis, tetapi untuk production sebaiknya gunakan domain sendiri.

Menambah Custom Domain

Bash
# Tambah domain via CLI
vercel domains add myapp.com

# Tambah subdomain
vercel domains add blog.myapp.com

# List semua domains
vercel domains ls

# Konfigurasi DNS:
# Type: A Record, Name: @, Value: 76.76.21.21
# Type: CNAME, Name: www, Value: cname.vercel-dns.com

# Wildcard domain (Pro/Enterprise plan)
vercel domains add "*.myapp.com"

# Redirect www ke apex domain
# Di vercel.json:
{
  "redirects": [
    { "source": "https://www.myapp.com/:path*", "destination": "https://myapp.com/:path*", "permanent": true }
  ]
}

9. Caching & ISR

Vercel memiliki caching layer yang sangat canggih yang terintegrasi langsung dengan Next.js. Incremental Static Regeneration (ISR) adalah fitur unggulan yang memungkinkan Anda meng-update konten statis tanpa rebuild seluruh site.

ISR di Next.js

TypeScript
// app/products/[id]/page.tsx — ISR dengan revalidation
export const revalidate = 60; // Revalidate setiap 60 detik

export default async function ProductPage({ params }) {
  const { id } = await params;
  const product = await fetch(
    `https://api.store.com/products/${id}`,
    { next: { revalidate: 60, tags: ['products'] } }
  );
  
  return (
    <div>
      <h1>{product.name}</h1>
      <p>Harga: Rp {product.price}</p>
    </div>
  );
}

// On-demand revalidation via API route
// app/api/revalidate/route.ts
import { revalidateTag } from 'next/cache';
import { NextRequest, NextResponse } from 'next/server';

export async function POST(request: NextRequest) {
  const { tag, secret } = await request.json();
  
  if (secret !== process.env.REVALIDATION_SECRET) {
    return NextResponse.json({ error: 'Invalid secret' }, { status: 401 });
  }
  
  revalidateTag(tag); // 'products'
  return NextResponse.json({ revalidated: true, tag });
}

10. Best Practices

Performance

Deployment

Pricing Tips

Plan Harga Cocok Untuk
Hobby (Free)$0/bulanPersonal project, portfolio, belajar
Pro$20/user/bulanTim kecil, startup, production apps
EnterpriseCustomPerusahaan besar, SLA, SSO, advanced security

📝 Quiz Pemahaman

Pertanyaan 1: Apa yang terjadi setiap kali Anda push code ke branch yang terhubung dengan Vercel?

a) Tidak ada yang terjadi
b) Deployment preview otomatis dibuat
c) Production langsung ter-update
d) Build error muncul di GitHub

Pertanyaan 2: Apa perbedaan utama antara Serverless Functions dan Edge Functions?

a) Edge Functions lebih mahal
b) Edge Functions berjalan di satu region, Serverless di banyak region
c) Edge Functions berjalan di 70+ edge locations, Serverless di satu region
d) Tidak ada perbedaan

Pertanyaan 3: Apa itu ISR (Incremental Static Regeneration)?

a) Build ulang seluruh site setiap kali ada perubahan
b) Render halaman di server setiap request
c) Regenerate halaman statis secara incremental tanpa rebuild seluruh site
d) Cache halaman secara permanen

Pertanyaan 4: Environment variable dengan prefix apa yang bisa diakses di client browser?

a) VERCEL_PUBLIC_*
b) PUBLIC_*
c) NEXT_PUBLIC_*
d) CLIENT_*

Pertanyaan 5: Berapa harga Vercel Hobby (Free) plan?

a) $10/bulan
b) $5/bulan
c) $0 (gratis)
d) $20/bulan
 ad-slot-wide">
🔍 Zoom
100%
🎨 Tema