通过 100+ 技巧合集学习 Nuxt!
部署

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 默认域名的信息。