Nuxt.js deployment on Gitlab

How to deploy your Nuxt.js application on Gitlab for continuous integration?

First create a Gitlab CI YAML file and name it .gitlab-ci.yml with the following commands:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
image: node

before_script:
  - npm install

cache:
  paths:
    - node_modules/

pages:
  script:
    - npm run generate
  artifacts:
    paths:
      - public
  only:
    - master

Then in nuxt.config.js, add these configuration lines:

1
2
3
4
5
6
7
8
9
/**
* Gitlab
*/
router: {
   base: '/whatEverName/',  
},
generate: {
   dir: 'public',
},

After running the CI job, and on the project’s repository, go to Settings then Pages and click on https://namespace.gitlab.io/whatEverName to navigate your application.