Skip to content

Instantly share code, notes, and snippets.

@michaelsynan
Last active April 15, 2023 00:41
Show Gist options
  • Save michaelsynan/307a267eff9b35e1b7f333da5e151e99 to your computer and use it in GitHub Desktop.
Save michaelsynan/307a267eff9b35e1b7f333da5e151e99 to your computer and use it in GitHub Desktop.
Deploy static Nuxt site to Github Pages with a custom domain

Easily Deploy a Static Nuxt Site on GitHub Pages w/ Custom Domain

Deploy to GitHub Pages and generate .nojekyll and CNAME files to output directory. Create & push to gh-pages subtree.

touch ./gitignore 
sed -i '/.output/d' .gitignore # remove .output from .gitignore
npm run generate
touch .output/public/.nojekyll    
echo "yourdomain.com" > .output/public/CNAME # only necessary for custom domain
git add .
git commit -m "Deploying static site"
git push origin main
git push origin HEAD:gh-pages # only needed first time
git subtree split --prefix .output/public -b gh-pages
git push -f origin gh-pages:gh-pages

Updating NPM Run Generate

You can automatically create .nojekyll and CNAME files by adding the following to the package.json generate script:

"generate": "nuxi generate && touch .output/public/.nojekyll && echo 'yourcustomdomain.com' > .output/public/CNAME",

Important Note

  • To deploy to GitHub Pages you must go to your repo settings, then pages and select Deploy from a branch followed by gh-pages for branch.
  • Import your CSS file in the app.vue script tag.

For more info on static site deployment using Nuxt, check out the documentation here.

@michaelsynan
Copy link
Author

Credit to @tduarte for his gist that originally helped me out with this issue: https://gist.github.com/tduarte/eac064b4778711b116bb827f8c9bef7b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment