211105 TIL React App Git에 배포하기 (학습 100일차)

김영진·2021년 11월 5일
0

Must Remember

  1. build 후에 배포하기 위해 package.json에 아래 구문으로 변경해준다.
  "scripts": {
      "start": "react-scripts start",
      "build": "react-scripts build",
      "predeploy": "npm run build",
      "deploy": "gh-pages -d build"
    },
  1. npm install gh-pages 설치
  2. package.json에 "homepage": "https://아이디.github.io/Movie_App_2021" 추가
  3. git init
    git add README.md
    git commit -m "first commit"
    git branch -M main
    git remote add origin https://github.com/아이디/Movie_App_2021.git
    git push -u origin main
    순서로 리포지토리에 업로드
  4. npm run deploy로 빌드 후 배포

※ 만약 BrowserRouter를 사용했을 경우 basename={process.env.PUBLIC_URL}를 써줘야 Home이 바로 보인다.

<BrowserRouter basename={process.env.PUBLIC_URL}>
  <Routes>
  	<Route path="/" element={<Friends />} />
  </Routes>
</BrowserRouter>
profile
UI개발자 in Hivelab

0개의 댓글