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

部署

  1. 以下是一个将您的站点部署到 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

了解更多

前往GitLab Pages 默认域名和 URL了解更多关于 GitLab Pages 默认域名的信息。