<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: surya nag</title>
    <description>The latest articles on DEV Community by surya nag (@suryanag0999).</description>
    <link>https://dev.to/suryanag0999</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2972876%2Fb03cb059-3d33-4bf7-a873-d489a5e1d9c0.jpeg</url>
      <title>DEV Community: surya nag</title>
      <link>https://dev.to/suryanag0999</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/suryanag0999"/>
    <language>en</language>
    <item>
      <title>How to Deploy a Vite React App to GitHub Pages</title>
      <dc:creator>surya nag</dc:creator>
      <pubDate>Mon, 24 Mar 2025 20:59:34 +0000</pubDate>
      <link>https://dev.to/suryanag0999/how-to-deploy-a-vite-react-app-to-github-pages-189i</link>
      <guid>https://dev.to/suryanag0999/how-to-deploy-a-vite-react-app-to-github-pages-189i</guid>
      <description>&lt;p&gt;How to Deploy a Vite React App to GitHub Pages – Step-by-Step Guide&lt;br&gt;
Deploy Vite React App to GitHub Pages&lt;br&gt;
MAR 25, 2025&lt;/p&gt;

&lt;p&gt;•&lt;/p&gt;

&lt;h1&gt;
  
  
  react
&lt;/h1&gt;

&lt;h1&gt;
  
  
  vite
&lt;/h1&gt;

&lt;h1&gt;
  
  
  github
&lt;/h1&gt;

&lt;h1&gt;
  
  
  git
&lt;/h1&gt;

&lt;p&gt;•&lt;/p&gt;

&lt;p&gt;2 mins read&lt;/p&gt;

&lt;p&gt;Create a New Project&lt;br&gt;
Let’s start by scaffolding a new React project using Vite:&lt;/p&gt;

&lt;p&gt;Copy&lt;br&gt;
npm create vite@latest&lt;br&gt;
Once the project is scaffolded, navigate to the project directory and install dependencies:&lt;/p&gt;

&lt;p&gt;Copy&lt;br&gt;
cd vite-react-deploy&lt;br&gt;
npm install&lt;br&gt;
Create a GitHub Repository&lt;br&gt;
Initialize Git, commit all the files, and push them to your new repository:&lt;/p&gt;

&lt;p&gt;Copy&lt;br&gt;
git init&lt;br&gt;
git add -A&lt;br&gt;
git commit -m "first commit"&lt;br&gt;
git branch -M main&lt;br&gt;
git remote add origin &lt;a href="https://github.com/%5Busername%5D/%5Brepo_name%5D.git" rel="noopener noreferrer"&gt;https://github.com/[username]/[repo_name].git&lt;/a&gt; # Replace with your username and repo URL&lt;br&gt;
git push -u origin main&lt;br&gt;
Your project is now successfully pushed to GitHub.&lt;/p&gt;

&lt;p&gt;Set Base Path in vite.config.ts&lt;br&gt;
If you skip this step, you'll get a 404 error for each asset in your project.&lt;/p&gt;

&lt;p&gt;Edit vite.config.ts as follows:&lt;/p&gt;

&lt;p&gt;Copy&lt;br&gt;
import { defineConfig } from "vite";&lt;br&gt;
import react from "@vitejs/plugin-react";&lt;/p&gt;

&lt;p&gt;export default defineConfig({&lt;br&gt;
  plugins: [react()],&lt;br&gt;
  base: "/vite-react-deploy/", // Replace with your repo name&lt;br&gt;
});&lt;br&gt;
Add a GitHub Workflow&lt;br&gt;
Create a deploy.yml file inside the .github/workflows directory and add the following content:&lt;/p&gt;

&lt;p&gt;Copy&lt;br&gt;
name: Deploy&lt;/p&gt;

&lt;p&gt;on:&lt;br&gt;
  push:&lt;br&gt;
    branches:&lt;br&gt;
      - main&lt;/p&gt;

&lt;p&gt;jobs:&lt;br&gt;
  build:&lt;br&gt;
    name: Build&lt;br&gt;
    runs-on: ubuntu-latest&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;steps:
  - name: Checkout repo
    uses: actions/checkout@v4  # Updated to latest version

  - name: Setup Node
    uses: actions/setup-node@v4  # Updated to latest version

  - name: Install dependencies
    uses: bahmutov/npm-install@v1

  - name: Build project
    run: npm run build

  - name: Upload production-ready build files
    uses: actions/upload-artifact@v4  # Updated to v4
    with:
      name: production-files
      path: ./dist
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;deploy:&lt;br&gt;
    name: Deploy&lt;br&gt;
    needs: build&lt;br&gt;
    runs-on: ubuntu-latest&lt;br&gt;
    if: github.ref == 'refs/heads/main'&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;steps:
  - name: Download artifact
    uses: actions/download-artifact@v4  # Updated to v4
    with:
      name: production-files
      path: ./dist

  - name: Deploy to GitHub Pages
    uses: peaceiris/actions-gh-pages@v4
    with:
      github_token: ${{ secrets.GITHUB_TOKEN }}
      publish_dir: ./dist
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Push the workflow changes:&lt;/p&gt;

&lt;p&gt;Copy&lt;br&gt;
git add -A&lt;br&gt;
git commit -m "deploy config"&lt;br&gt;
git push&lt;br&gt;
Configure GitHub Actions Permissions&lt;br&gt;
Go to Settings → Actions → General.&lt;/p&gt;

&lt;p&gt;Scroll down to Workflow Permissions.&lt;/p&gt;

&lt;p&gt;Choose Read and Write and save.&lt;/p&gt;

&lt;p&gt;Re-run failed actions if needed.&lt;/p&gt;

&lt;p&gt;Configure GitHub Pages&lt;br&gt;
Navigate to Settings → Pages.&lt;/p&gt;

&lt;p&gt;Under Source, choose Deploy from branch.&lt;/p&gt;

&lt;p&gt;Select the gh-pages branch.&lt;/p&gt;

&lt;p&gt;Click Save.&lt;/p&gt;

&lt;p&gt;Once the workflow finishes successfully, you’ll see a new deployment on GitHub Pages. Click the link to access your deployed Vite React application!&lt;/p&gt;

&lt;p&gt;🚀 Congratulations! Your Vite React App is live!&lt;/p&gt;

</description>
      <category>react</category>
      <category>vite</category>
      <category>github</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
