Pullanner project - husky 설정

이소라·2023년 2월 22일

Pullanner project

목록 보기
3/11

husky 설치

  • husky를 devDependencies에 설치합니다.
yarn add -D husky
  • Git hook을 사용할 수 있게 다음 명령어 실행합니다.
yarn husky install
  • install한 후 자동적으로 Git hook 가질 수 있도록, package.json에 postinstall 설정 추가합니다.
{
  "private": true,
  "scripts": {
    ...,
    "postinstall": "husky install"
  }
}
  • package.json에 사용할 script 명령어를 추가합니다.
    • Prettier
      • --cache : cache 이후 값이 cache key로 사용되고, 그 값이 변했을 때만 fomat됩니다.
      • -write : cache를 저장합니다.
    • ESLint
      • --cache : 파일에 대한 정보를 저장하고, 변경된 파일 내용만 lint합니다.
{
  "private": true,
  "scripts": {
    ...,
    "format": "prettier --cache --write .",
    "lint": "eslint --cache ."
  }
}
  • husky add <file> [cmd]를 사용하여 husky 명령어를 작성합니다.
npx husky add .husky/pre-commit "yarn format"
npx husky add .husky/pre-push "yarn lint"
  • git repository에 husky 파일 추가합니다.
git add .husky/pre-commit
git add .husky/pre-push

참고

0개의 댓글