部署
GitHub Pages
将您的 Nuxt 应用程序部署到 GitHub Pages 基础设施。
Nuxt 支持通过最少的配置部署到 GitHub Pages。
GitHub Pages 仅支持静态站点,Nuxt 会将您的应用程序预渲染为静态 HTML 文件。
如果您**没有**使用自定义域名,则需要为构建步骤设置
NUXT_APP_BASE_URL
为您的仓库slug。**示例**:https://<user>.github.io/<repository>/
: NUXT_APP_BASE_URL=/<repository>/ npx nuxt build --preset github_pages
设置
按照步骤 创建 GitHub Pages 站点。
部署
以下是一个使用 github_pages
预设将您的站点部署到 GitHub Pages 的 GitHub Actions 工作流示例
.github/workflows/deploy.yml
# https://github.com/actions/deploy-pages#usage
name: Deploy to GitHub Pages
on:
workflow_dispatch:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: "20"
# Pick your own package manager and build script
- run: npm install
- run: npx nuxt build --preset github_pages
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./.output/public
# Deployment job
deploy:
# Add a dependency to the build job
needs: build
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source
# Deploy to the github_pages environment
environment:
name: github_pages
url: ${{ steps.deployment.outputs.page_url }}
# Specify runner + deployment step
runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4