DEV Community

SHARKZTECH
SHARKZTECH

Posted on

Hosting vite react app to github pages

Hosting a Vite-powered React app on GitHub Pages is a great way to quickly and easily deploy your app to the web. Below is a guide of how to do that:
step 1: install "gh-pages"

npm i gh-pages or yarn install gh-pages
Enter fullscreen mode Exit fullscreen mode

Github pages will help you automate the process of deployment
step 2: add the following in your 'package.json' to configure it to use "gh-pages" in deployment

...
  "scripts": {
...
    "build": "vite build",
    "predeploy": "npm run build",
    "deploy": "gh-pages -d dist",
...
  },
...
Enter fullscreen mode Exit fullscreen mode

step 3:add base in "vite.config.js" with github repository name as the value within slashes

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

export default defineConfig({
  base:"/repository_name/",
  plugins: [react()],
})
Enter fullscreen mode Exit fullscreen mode

step 4: run npn run build
step 5: run npm run deploy

Please note that, the above steps are for static hosting. If you have a dynamic web application then you need to look for other hosting options such as AWS Amplify, Firebase Hosting, Heroku, etc.

AWS Q Developer image

Your AI Code Assistant

Generate and update README files, create data-flow diagrams, and keep your project fully documented. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (1)

Collapse
 
aleksandrpod profile image
Aleksandr Podmazko • Edited

Gosh I had millions of variation but still without result.
My repo has "dist" folder but gh-page not using it for deploy. On the page I see partials of "handlebars" but not a builded page.
And I set up "gh-page" branch for building in settings>pages - no result

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay