Skip to content

Commit ec83ab6

Browse files
committed
Add GitHub Pages deployment
1 parent 9b1edfe commit ec83ab6

File tree

3 files changed

+90
-6
lines changed

3 files changed

+90
-6
lines changed

.github/workflows/github-pages.yaml

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Deploy Next.js example to GitHub Pages
2+
3+
on:
4+
# Runs on pushes targeting the default branch
5+
push:
6+
branches: ["main"]
7+
8+
# Allows you to run this workflow manually from the Actions tab
9+
workflow_dispatch:
10+
11+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
12+
permissions:
13+
contents: read
14+
pages: write
15+
id-token: write
16+
17+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
18+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
19+
concurrency:
20+
group: "pages"
21+
cancel-in-progress: false
22+
23+
jobs:
24+
# Build job
25+
build:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
- uses: pnpm/[email protected]
31+
name: Install pnpm
32+
with:
33+
run_install: false
34+
- name: Setup Node
35+
uses: actions/setup-node@v4
36+
with:
37+
node-version: "20"
38+
cache: pnpm
39+
- name: Setup Pages
40+
uses: actions/configure-pages@v5
41+
with:
42+
# Automatically inject basePath in your Next.js configuration file and disable
43+
# server side image optimization (https://nextjs.org/docs/api-reference/next/image#unoptimized).
44+
#
45+
# You may remove this line if you want to manage the configuration yourself.
46+
static_site_generator: next
47+
- name: Restore cache
48+
uses: actions/cache@v4
49+
with:
50+
path: |
51+
.next/cache
52+
# Generate a new cache whenever packages or source files change.
53+
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
54+
# If source files changed but packages didn't, rebuild from a prior cache.
55+
restore-keys: |
56+
${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-
57+
- name: Install dependencies
58+
run: pnpm install --frozen-lockfile
59+
- name: Build with Next.js
60+
run: pnpm run build
61+
working-directory: example
62+
- name: Upload artifact
63+
uses: actions/upload-pages-artifact@v3
64+
with:
65+
path: ./example/out
66+
67+
# Deployment job
68+
deploy:
69+
environment:
70+
name: github-pages
71+
url: ${{ steps.deployment.outputs.page_url }}
72+
runs-on: ubuntu-latest
73+
needs: build
74+
steps:
75+
- name: Deploy to GitHub Pages
76+
id: deployment
77+
uses: actions/deploy-pages@v4

example/next.config.mjs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/** @type {import('next').NextConfig} */
2-
const nextConfig = {};
2+
const nextConfig = {
3+
output: 'export'
4+
};
35

46
export default nextConfig;

example/src/app/page.tsx

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
// import Image from "next/image";
2-
import { redirect } from "next/navigation";
3-
import styles from "./page.module.css";
4-
51
export default function Home() {
6-
redirect("/page1");
2+
return (
3+
<div>
4+
<div>
5+
<a href="/page1">App Router</a>
6+
</div>
7+
<div>
8+
<a href="/page1">Pages Router</a>
9+
</div>
10+
</div>
11+
);
712
}

0 commit comments

Comments
 (0)