gitlabnuxt.jsgitlab-ci

Nuxt 3 on Gitlab Pages


I am trying to deploy my static Nuxt 3 site on Gitlab pages, which I used to with Nuxt 2 changing the directory name dist to the gitlab requested public.

As Nuxt 3 now renamed what used to be called static with public, I cannot do the same change.

Nuxt 3 now generates the site inside .output/public so here is my gitlab-ci.yml

# The Docker image that will be used to build your app
  image: node:20.4.0
# Functions that should be executed before the build script is run
  before_script:
    - yarn install
  pages:
    script:
      - yarn generate
  artifacts:
    paths:
      # The folder that contains the files to be exposed at the Page URL
      - .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

I downloaded the artifacts after the pipeline fails and .output/public is there, including index.html inside /public.

I have also tried just 'public' as path, but in that case the artifacts will contain the actual public folder of nuxt (ex static).


Solution

  • Actually, there is an even more "simple" way to do this using the pages:publish option from the GitLab CI reference without having to deal with directories or changing your nuxt config

    pages:
      # ...
      script:
        - yarn generate
      artifacts:
        paths:
          - .output/public
      publish: .output/public