Programmer's Picnic
React Lesson by Champak Roy
React + Vite + GitHub Pages

Create, Run, Build and Deploy React on GitHub Pages

A practical screenshot-based lesson for creating a React app with Vite, running it locally, pushing it to GitHub, deploying with GitHub Actions, and connecting react.learnwithchampak.live.

1. What we are building

We will create a React app, run it locally, build it automatically on GitHub, and publish it on GitHub Pages using a custom domain.

Final URL: https://react.learnwithchampak.live/
Create React
Run Locally
Push GitHub
GitHub Actions
Live Website
Important: GitHub Pages should serve the built dist output, not raw files like src/main.jsx.

2. Create the React app with Vite

Open Command Prompt or PowerShell and run:

D:
npm create vite@latest react
Command Prompt showing npm create vite latest react command
Step 1: Start creating a Vite project named react.

When npm asks to install create-vite, type y and press Enter.

Vite framework selection screen with React selected
Step 2: Select React as the framework.
Vite variant selection screen with JavaScript selected
Step 3: Select JavaScript as the variant.
Vite install with npm and start now prompt
Step 4: Choose Yes when Vite asks to install and start now.

3. Run the React app locally

After installation, Vite starts a local development server. Open the URL shown in the terminal.

Vite local development server ready with localhost 5173
Vite is ready at http://localhost:5173/.
React Vite app running in Chrome browser
The default React + Vite app running successfully in the browser.

To stop the server, press Ctrl + C, then type y.

Command Prompt showing terminated Vite and npm install
After stopping the server, enter the project folder and run npm install if needed.
cd react
npm install
npm run dev
Command Prompt running npm run dev
Run the development server again using npm run dev.
Vite development server running again
Vite starts again and gives the local URL.

4. Add the custom domain file

For GitHub Pages custom domain support, create a CNAME file inside the public folder.

echo react.learnwithchampak.live > public/CNAME
Command Prompt creating public CNAME file
Create public/CNAME with the custom domain.
Spelling matters: the domain must be react.learnwithchampak.live, not .liv.

Vite config for custom domain

For a custom domain, keep base: '/' in vite.config.js.

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

export default defineConfig({
  plugins: [react()],
  base: '/',
})

5. Create the GitHub Actions deploy workflow

Create the workflow folder:

mkdir -p .github/workflows
PowerShell creating github workflows folder
Create .github/workflows for the deployment workflow.

Create this file:

.github/workflows/deploy.yml

Use this complete workflow:

name: Deploy React site to GitHub Pages

on:
  push:
    branches:
      - main

  workflow_dispatch:

permissions:
  contents: read
  pages: write
  id-token: write

concurrency:
  group: github-pages
  cancel-in-progress: false

jobs:
  build:
    name: Build React app
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: npm

      - name: Install dependencies
        run: npm ci

      - name: Build with Vite
        run: npm run build

      - name: Upload dist folder
        uses: actions/upload-pages-artifact@v3
        with:
          path: ./dist

  deploy:
    name: Deploy to GitHub Pages
    needs: build
    runs-on: ubuntu-latest

    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}

    steps:
      - name: Deploy site
        id: deployment
        uses: actions/deploy-pages@v4
This workflow builds your app and deploys only the dist folder.

6. Commit and push to GitHub

git init
git add .
git commit -m "Initial React app for GitHub Pages"
git branch -M main
git remote add origin https://github.com/programmer-s-picnic/react.git
git push -u origin main
PowerShell showing git commit for React app
Commit the React app, CNAME file, Vite config, and workflow file.
PowerShell showing git push to GitHub
Push the first version to GitHub.

If you later modify only the workflow, commit and push again:

git add .github/workflows/deploy.yml
git commit -m "Add GitHub Pages deploy workflow"
git push
PowerShell showing workflow commit and push
Commit and push workflow updates if needed.

7. Configure GitHub Pages correctly

Open the repository on GitHub:

Repository → Settings → Pages

Set the source to:

Source: GitHub Actions
Do not use: Deploy from a branch → main / root. That publishes the raw source files and causes the JSX MIME type error.

Add the custom domain:

react.learnwithchampak.live

Then enable:

Enforce HTTPS

In DNS, add:

Type: CNAME
Name: react
Value: programmer-s-picnic.github.io

8. Fix the MIME type text/jsx error

The common error is:

Failed to load module script:
Expected a JavaScript-or-Wasm module script
but the server responded with a MIME type of "text/jsx".

This means GitHub Pages is serving the raw file:

/src/main.jsx

The fix is to use:

Settings → Pages → Source → GitHub Actions
After the GitHub Actions workflow succeeds, the site serves built files from dist/assets, and the error goes away.

9. Screenshot recap

Here is the whole process as a visual recap.

10. Final checklist

ItemCorrect value
Local run commandnpm run dev
Custom domain filepublic/CNAME
CNAME contentreact.learnwithchampak.live
Vite basebase: '/'
Workflow file.github/workflows/deploy.yml
GitHub Pages sourceGitHub Actions
DNS recordreact → programmer-s-picnic.github.io
Final websitehttps://react.learnwithchampak.live/