Skip to content

Commit 0f16e86

Browse files
Added basePath & assetPrefix conditional for github pages static build.
1 parent d1991bc commit 0f16e86

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

.github/workflows/nextjs-static-gh-pages.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ jobs:
6565
- name: 🏗 Generate Static Build
6666
env:
6767
NEXT_OUTPUT_MODE: export
68+
GITHUB_PAGES: 1
6869
run: |
69-
echo "Building static files..."
70+
echo "Building static files for GitHub Pages..."
7071
pnpm build
7172
touch out/.nojekyll
7273

next.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ const isStaticExport = process.env.NEXT_OUTPUT_MODE === 'export'
55

66
console.log(`Next.js static export mode: ${isStaticExport}`)
77

8+
const repoName = 'codebuilder-frontend';
9+
const isGithubPages = !!process.env.GITHUB_PAGES;
10+
811
const nextConfig: NextConfig = {
912
/**
1013
* FIX: The 'turbo' settings have been moved to the top-level 'turbopack' property
@@ -16,6 +19,8 @@ const nextConfig: NextConfig = {
1619

1720
// Conditionally set the output mode for the build.
1821
output: isStaticExport ? 'export' : undefined,
22+
basePath: isGithubPages ? `/${repoName}` : '',
23+
assetPrefix: isGithubPages ? `/${repoName}/` : '',
1924

2025
allowedDevOrigins: ['https://new.codebuilder.org', 'https://new.codebuilder.org:443'], // resolves the CORS warning
2126

0 commit comments

Comments
 (0)