部署
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