GitLab Pages
將您的 Nuxt 應用程式部署到 GitLab Pages。
Nuxt 支援部署到GitLab Pages只需少量配置。
GitLab Pages 僅支援靜態站點,Nuxt 會將您的應用程式預渲染為靜態 HTML 檔案。
如果您未使用自定義域名,您需要在構建步驟中將
NUXT_APP_BASE_URL
設定為您的倉庫 slug。示例:https://<group/user>.gitlab.io/<repository>/
:NUXT_APP_BASE_URL=/<repository>/ npm run generate
部署
- 以下是一個將您的站點部署到 GitLab Pages 的 GitLab Pages 工作流示例
.gitlab-ci.yml
# Job name has to be `pages`. See https://docs.gitlab.com/ee/user/project/pages/#how-it-works
pages:
image: node
before_script:
- npm ci --cache .npm --prefer-offline
script:
# Specify the steps involved to build your app here
- npm run generate
cache: # https://docs.gitlab.com/ee/ci/caching/#cache-nodejs-dependencies
key:
files:
- package-lock.json
paths:
- .npm/
artifacts:
paths:
# The directory that contains the built files to be published
- .output/public
# The directory that contains the built files to be published
publish: .output/public
rules:
# This ensures that only pushes to the default branch
# will trigger a pages deploy
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH