Skip to content

Instantly share code, notes, and snippets.

@officialrajdeepsingh
Created September 16, 2025 12:01
Show Gist options
  • Select an option

  • Save officialrajdeepsingh/c4bf7c5f57c45c268684867f901b34b7 to your computer and use it in GitHub Desktop.

Select an option

Save officialrajdeepsingh/c4bf7c5f57c45c268684867f901b34b7 to your computer and use it in GitHub Desktop.
Deploy a Next.js application on GitHub Pages using PNPM package manager.
# .github/workflows/deploy.yml
name: Deploy to GitHub Pages
on:
push:
branches:
- main
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20" # or "18", "22" (stable) – Node 24 is experimental
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9 # or latest version you need
run_install: false
- name: Install dependencies
run: pnpm install
- name: Build Next.js app
run: pnpm build
env:
NEXT_PUBLIC_BASE_URL: http://localhost:3000 // Add an environment variable.
- name: Export static site
run: pnpm build
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./out
- name: Clean up
run: rm -rf ./out
# Notes:
# - Make sure your Next.js app supports static export (`next export`).
# - Set "output: 'export'" in your next.config.js/ts if using Next.js 13+ app directory.
# - The published site will be available at https://<username>.github.io/<repo-name>/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment