writing-skills
writing-skills
Use when creating new skills, editing existing skills, or verifying skills work before deployment
deploy-to-vercelDeploy a Next.js application to Vercel. Covers project linking, environment variables, preview deployments, custom domains, and production deployment configuration. Use when deploying a Next.js app for the first time, setting up preview deployments for pull requests, configuring custom domains, or managing environment variables in a production Vercel deploy…
Independent GitHub snapshot · Automated classification · Original documentation governs
部 Next.js 應於 Vercel 含生產配。
npm run build
得: 構建無錯成。
敗: 修構建錯後部。常見:TypeScript 錯、缺依賴、無效引入。
npm install -g vercel
得: vercel 命令全局可用,vercel --version 印版本。
敗: 權限錯→sudo npm install -g vercel 或配 npm 用戶本地前綴。node --version 驗 Node.js 已裝。
# Login to Vercel
vercel login
# Deploy (first time: creates project)
vercel
# Follow prompts:
# - Set up and deploy? Y
# - Which scope? (select your account)
# - Link to existing project? N (for new projects)
# - Project name: my-app
# - Directory: ./
# - Override settings? N
得: 預覽 URL 給(如 https://my-app-xxx.vercel.app)。
敗: vercel login 失→查網,試瀏覽器認證。部失→察構建輸出錯——Vercel 用潔環境,諸依賴須於 package.json。
# Add environment variables
vercel env add DATABASE_URL production
vercel env add API_KEY production preview
# List environment variables
vercel env ls
或經 Vercel 儀板:Project Settings > Environment Variables。
得: vercel env ls 示諸需變量配於正環境(production、preview、development)。
敗: 運行時無變量→驗目標環境匹(production vs preview)。加變量後重部——現部不自動取新變量。
vercel --prod
得: 生產 URL 可用(如 https://my-app.vercel.app)。
敗: vercel logs 或 Vercel 儀板察部署日誌。常見:生產環境缺變量、構建命與本地異。
得: Vercel 儀板示 GitHub 倉已連,後推 main 自動觸發生產部署。
敗: 倉未現於引入列→查 Vercel GitHub 應有倉訪問權。至 GitHub Settings > Applications > Vercel 授權。
vercel domains add my-domain.com
或經儀板:Project Settings > Domains。
按 Vercel 指示更 DNS 記錄(通常 CNAME 或 A)。
得: vercel domains ls 示自定域已配,DNS 傳播畢(至 48 時),域解至 Vercel 部署。
敗: 示「Invalid Configuration」→驗 DNS 記錄精匹 Vercel 指示。dig my-domain.com 或在線 DNS 檢確傳播。
建 vercel.json 進階設:
{
"framework": "nextjs",
"regions": ["iad1"],
"headers": [
{
"source": "/api/(.*)",
"headers": [
{ "key": "Cache-Control", "value": "no-store" }
]
}
]
}
得: vercel.json 存項根,下部取配(於 Vercel 儀板構建日誌可見)。
敗: 配忽→jq . vercel.json 驗有效 JSON。查 Vercel 文檔匹框架版本,某設可遷 next.config.ts。
npm run build 本地成package.json 非僅全局裝。.env.local。不同環境(production、preview、development)分別變量集。package.json engines 字段設 Node.js 版本。.vercelignore 排除不需檔。scaffold-nextjs-appsetup-tailwind-typescriptconfigure-git-repository