Front-end/React

vite+react 깃헙 배포 방법

Alraffe 2023. 10. 5. 18:36

연휴동안 정말.. 이거 때문에 고생 너무 많이 했는데 은혜로운 분이 정리해놓은 글 덕분에 해결할 수 있었다.

 

우선, 에러 상황을 정리해보면 빈화면이다.. 코드를 보면 루트 아래로 어떤 파일도 들어오지 않는다. 당연 콘솔에 찍히는 에러코드도 404.

 

원인은 파일의 index.html에서 경로를 못찾는 것인데.. 몇몇 사람들은 같은 이유의 해결방법으로 경로를 수정하던데 그 방법으로는 해결되지 않았다.

 

해결하기 위해서는 몇가지를 수정해야만했다.

1. tsconfig.json에서 "noUnusedLocals", "noUnusedParameters"를 false로 수정.

2. vite.config.ts에서 base 설정값을 '/[레포이름]/' 으로 지정한다. 이 레포이름은 깃헙에 레포이름과 동일하게!

3. .github/workflows/deploy.yml 을 생성하고 아래 내용을 넣는다.

4. 그리고 푸쉬를 하면 해결~~

 

name: Deploy static content to Pages

on:
  push:
    branches: ['main']

  workflow_dispatch:

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

concurrency:
  group: 'pages'
  cancel-in-progress: true

jobs:
  deploy:
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Set up Node
        uses: actions/setup-node@v3
        with:
          node-version: 18
          cache: 'npm'
      - name: Install dependencies
        run: npm install
      - name: Build
        run: npm run build
      - name: Setup Pages
        uses: actions/configure-pages@v3
      - name: Upload artifact
        uses: actions/upload-pages-artifact@v1
        with:
          path: './dist'
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v1

 

 

 

참고
https://leirbag.tistory.com/146

정말 감사합니다 🙇🏻‍♀️