Deploying a Nuxt3 project on GitHub Pages
In order to publish this blog project I prepared with Nuxt 3, I went through many sources and finally learned to publish the Nuxt3 project on GitHub Pages. Since it is not available in many places, I will show you.
Deploying a Nuxt3 project on GitHub Pages involves a few steps:
- First, you need to generate the static files of your Nuxt3 project. To do this, run the following command:
For Server Side Rendering (SSR):yarn build
ornpm build
For Static Generation:yarn generate
ornpm generate
This will create adist
folder in your project directory that contains the generated static files. - Next, you need to create a new repository on GitHub to host your project. Make sure to initialize the repository with a README file.
- Once your repository is created, you need to install the
gh-pages
package. This package allows you to deploy your static files to GitHub Pages. To install the package, run the following command:npm install gh-pages --save-dev
- After installing
gh-pages
, open yourpackage.json
file and add the following lines to it:"scripts": { "deploy": "gh-pages -d dist" }
This will add a new script nameddeploy
to your project, which will deploy your static files to GitHub Pages. - Now, you can deploy your Nuxt3 project by running the following command:
npm run deploy
- You need to configure your repository settings to use the
gh-pages
branch as your GitHub Pages source. To do this, go to your repository's settings and scroll down to the GitHub Pages section. From there, select thegh-pages
branch as your source and save your changes. - Finally, DO NOT FORGET to add an empty file named
.nojekyll
to GitHub Pages. I wandered around many sources for a long time, but finally, I was able to publish my page like this.
Once you complete the deployment, your GitHub Pages will look like this: