Vercel
Prerequisites
$ npx -v
6.14.13
$ npx create-next-app@latest
Deploy with CLI
-
Install Vercel Locally
$ npm i -g vercel $ vercel -v Vercel CLI 28.10.1 28.10.1
-
Token
- go vercel tokens page to create a token
EsI73PNCtxqT72GtUTZgtydf
, denotes as$VERCEL_TOKEN
in following commands.
- go vercel tokens page to create a token
-
Create Vercel Project
vercel pull --yes --token=$VERCEL_TOKEN
-
Deploy
-
preview environment
vercel deploy --token=$VERCEL_TOKEN
-
production environment
vercel deploy --prod --token=$VERCEL_TOKEN
-
GitLab CI/CD
-
Add Vercel Token to CI/CD variables
-
visit
https://gitlab.com/${user}/${project}/-/settings/ci_cd
- add vercel token with key
$VERCEL_TOKEN
and uncheckedprotect variable
- add vercel token with key
-
-
Add script
.gitlab-ci.yml
to main branchdefault: image: node:16.16.0 deploy_preview: stage: deploy only: - preparing script: - npm install --global vercel - vercel pull --yes --environment=preview --token=$VERCEL_TOKEN - vercel build --token=$VERCEL_TOKEN - vercel deploy --prebuilt --token=$VERCEL_TOKEN deploy_production: stage: deploy only: - main script: - npm install --global vercel - vercel pull --yes --environment=production --token=$VERCEL_TOKEN - vercel build --prod --token=$VERCEL_TOKEN - vercel deploy --prebuilt --prod --token=$VERCEL_TOKEN
Github CICD
-
Create token at Vercel Perconal Account Setting page
- Add PAT at
Repo > settings > Secrets > Actions > New repository secret
- Add token from step 1. as
VERCEL_TOEKN
. - If you can't find the setting page, try https://github.com/${username}/${reponame}/settings/secrets/actions.
- Add token from step 1. as
- add CI/CD script
.github/workflows/vercel.yml
tomain
branch
name: vercel
on:
push:
branches: [ preparing ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout@v3
- run: |
npm install --global vercel
vercel pull --yes --environment=preview --token=$
vercel deploy --token=$
- push your code to branch
preparing
and check vercel dashborad.