How to deploy a nuxt app to GitHub Pages
In this tutorial, we are going to learn about how to host your nuxt app to GitHub pages by using the command line.
Deploying to GitHub Pages
- First, create a new repository in GitHub and push your nuxt app to it.
- Now, open your
nuxt.config.js
file and add the following configuration to theexport default
object.
nuxt.config.js
export default {
mode: 'static',
router: {
base: '/your-github-repository-name/'
},
// other config goes here
}
- Install the
gh-pages
package by using the below command.
npm install gh-pages --save-dev
- Add the following deploy commands to your
package.json
filescripts
object.
"predeploy": "nuxt generate",
"deploy": "gh-pages -d dist"
- Run the following command to successfully deploy your app to GitHub pages.
npm run deploy
Now, open your nuxt app GitHub repository and click on the settings
tab, if your scroll down to the GitHub Pages
section you will see a nuxt app live URL like this.