Github pages로 배포하기

깃허브 페이지스는 git repogitory의 코드를 호스팅 해주는 기능이다. 

작성한 코드를 빌드해서 올려서 호스팅할 수 있다. 

처음엔 빌드하지 않고 올려서 readme.md만 출력되었는데 생각해보니 어처구니 없는 실수였다..

 

gh-pages 패키지 설치

npm install gh-pages --save-dev

or

yarn add gh-pages --save-dev

 

 

github pages를 사용하기 위해 파일을 빌드하고 배포할 수 있게 해주느 패키지인 gh-pages를 받아야한다.

 

Package.json 수정

아래왜 같이 수정해준다.

 

"homepage": "웹사이트 url"
"predeploy": "npm run build" or "yarn build" 
"deploy": "gh-pages -d build"

{
  "homepage": "https://aingface.github.io/my-resume",
  "name": "resume",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.14.1",
    "@testing-library/react": "^13.0.0",
    "@testing-library/user-event": "^13.2.1",
    "@types/jest": "^27.0.1",
    "@types/node": "^16.7.13",
    "@types/react": "^18.0.0",
    "@types/react-dom": "^18.0.0",
    "gh-pages": "^5.0.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "5.0.1",
    "styled-components": "^5.3.9",
    "typescript": "^5.0.2",
    "web-vitals": "^2.1.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "predeploy": "yarn build",
    "deploy": "gh-pages -d build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@types/styled-components": "^5.1.26",
    "@typescript-eslint/eslint-plugin": "^5.56.0",
    "@typescript-eslint/parser": "^5.56.0",
    "eslint": "^8.36.0",
    "prettier": "^2.8.6"
  }
}

 

그리고 배포하기 

 

npm run deploy

or 

yarn deploy

 

배포에 성공하면 프로젝트가 있는 Repository에 gh-pages라는 브랜치가 생성됩니다.

 

디렉토리를 gh-pages로 해야한다

 

 

그런데.. 매번 이렇게 배포하기 귀찮고 remote repository에 push 할 때마다 새로 배포되게 할 수는 없을까? 

당연히 방법이 있다. 그것은 Github actions

 

다음 글에서 다뤄보겠다. 

+ Recent posts