GitHub Pages
GitHub Pages is ideal for documentation and static sites. Use static export (e.g., Next.js output: 'export') and publish the out/ directory to the gh-pages branch using your CI workflow or the gh-pages npm package. The CLI helps with opening dashboards and general docs flows; it does not publish to GitHub Pages directly.
Prerequisites
- A GitHub repo with an
originremote - Push permissions for
gh-pages - Pages configured to build from the
gh-pagesbranch (root)
Static export (Next.js 15)
Next 15 supports static export via output: 'export'. Add this to next.config.ts:
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
output: 'export',
images: { unoptimized: true },
trailingSlash: true,
// If hosting at https://<owner>.github.io/<repo>, set basePath/assetPrefix to '/<repo>'
// basePath: '/<repo>',
// assetPrefix: '/<repo>'
}
export default nextConfig
Then build:
pnpm build
This produces out/. Ensure a .nojekyll marker exists so _next/* assets are served by GitHub Pages.
Open dashboard
opd open github
This opens the repository’s Pages settings/dashboard.
CI (GitHub Actions)
Use a workflow (e.g., deploy-docs.yml) to publish the out/ folder with the gh-pages npm package or actions like peaceiris/actions-gh-pages.
If your site is hosted at /repo, set NEXT_BASE_PATH=/<repo> in the build step, or set basePath/assetPrefix in next.config.ts.
Troubleshooting
- Icons or images missing: ensure
basePathandassetPrefixare set to/<repo>innext.config.ts(or setNEXT_BASE_PATH=/<repo>in CI), and.nojekyllexists inout/. - Seeing the repo README instead of the site: set Pages source to
gh-pages→/ (root)underSettings → Pages. - Custom domain: add a
CNAMEfile inpublic/and configure DNS to point to<owner>.github.io.