Giter VIP home page Giter VIP logo

portfolio's Introduction

Deploy to GitHub Pages CodeFactor

Create a React Project Using Vite and Deploy It to GitHub Pages

Create the Project

Scaffold the project using Vite (note the extra double dash required for npm 7+):

$ npm create vite@latest project-name -- --template react

Install the dependencies:

$ cd project-name
$ npm install

If the app is going to be deployed to a folder, set base in vite.config.js:

export default defineConfig({
    ...
    base: '/project-name/',
    ...
})

To run the development server:

$ npm run dev

To build the app and test it locally:

$ npm run build
$ npm run preview

Install and Setup Additional Packages if Required

I'm using Tailwind CSS and React Router in this project.

Install Tailwind CSS:

$ npm install -D tailwindcss postcss autoprefixer
$ npx tailwindcss init -p

Configure template paths in tailwind.config.cjs:

module.exports = {
    content: [
        "./index.html",
        "./src/**/*.{js,ts,jsx,tsx}",
    ],
    ...
}

Install React Router:

$ npm install react-router-dom

If the app is going to be deployed to a folder, make sure to set basename for the router in src/main.jsx:

ReactDOM.createRoot(document.getElementById('root')).render(
    <React.StrictMode>
        <BrowserRouter basename='/project-name/'>
            ...

Create Deployment Workflow

Create a new file .github/workflows/deploy.yml:

name: Deploy to GitHub Pages

on:
  # Runs on pushes and pull requests to "main" branch
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

  # Allow to run manually from the Actions tab
  workflow_dispatch:

# Set permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
  contents: read
  pages: write
  id-token: write

# Allow one concurrent deployment
concurrency:
  group: 'pages'
  cancel-in-progress: true

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

    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 18

      - name: Install dependencies
        run: npm ci

      - name: Build project
        run: npm run build

      - name: Setup Pages
        uses: actions/configure-pages@v3

      - name: Upload Pages artifact
        uses: actions/upload-pages-artifact@v1
        with:
          path: ./dist

  deploy:
    name: Deploy
    needs: build
    runs-on: ubuntu-latest

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

    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v1

https://vitejs.dev/guide/static-deploy.html#github-pages

Setup GitHub Repository

Create the local repository:

$ git init
$ git add --all
$ git commit -m "Initial commit"

Go to https://github.com/new and create a new GitHub repository. Make sure it's Public, otherwise you won't be able to deploy it to GitHub pages.

In the repository's Pages configuration choose "GitHub Actions" as the source of deployment.

After creating the repository, follow the provided instructions and push your project to GitHub.

To be continued...

portfolio's People

Contributors

david-phx avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.