Service GitHub Pages
Polen supports deployment to GitHub Pages with static site generation (SSG) builds.
Quick Start
Enable GitHub Pages in your repository:
- Go to Settings → Pages
- Under "Source", select "GitHub Actions"
Create a deployment workflow in
.github/workflows/deploy.yml
:
name: Deploy to GitHub Pages
on:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- run: npm ci
- name: Build site
run: npx polen build --architecture ssg --base /<repository-name>/
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./build
deploy:
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
Update the base path in the workflow to match your repository name
Push to main - the deployment will run automatically
Configuration
Base Path
When deploying to GitHub Pages, you need to configure the base path:
Via CLI
npx polen build --architecture ssg --base /your-repo-name/
Via Config File
// polen.config.ts
export default defineConfig({
build: {
base: '/your-repo-name/',
},
})
Build Architecture
GitHub Pages requires static files, so use the ssg
(Static Site Generation) architecture:
npx polen build --architecture ssg
Advanced Features
Multiple Environments
Use Polen's rebase feature to deploy the same build to different paths:
# Build once
npx polen build --architecture ssg
# Deploy to staging
npx polen static rebase ./build --new-base-path /staging/ --mode copy --target ./build-staging
# Deploy to production
npx polen static rebase ./build --new-base-path /production/ --mode copy --target ./build-prod
PR Preview Deployments
For pull request previews, you can use the base path with PR numbers:
- name: Build PR preview
run: npx polen build --architecture ssg --base /pr-${{ github.event.number }}/
Custom Domain
To use a custom domain:
Create a
CNAME
file in your build output:yaml- name: Add CNAME run: echo "docs.example.com" > ./build/CNAME
Configure your domain's DNS to point to GitHub Pages
Troubleshooting
Build Output Directory
Polen's SSG builds output to the build/
directory by default. Make sure your workflow uploads from the correct path:
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./build # Not ./dist
Base Path Issues
- Base paths must start and end with
/
- Use the same base path in your build command and GitHub Pages settings
- For root deployments, use
/
as the base path
404 Errors
If you get 404 errors:
- Check that GitHub Pages is enabled in repository settings
- Verify the base path matches your deployment URL
- Ensure the workflow completed successfully
- Check that all assets use relative paths
Example Projects
See the Polen deployment workflow for a complete working example.