React 초기 프로젝트 세팅 (eslint, husky etc..)

2022. 4. 20. 01:10·WEB/React
반응형

husky, commitlint

husky는 git의 hook들을 쉽게 관리하게 해주는 툴입니다. husky에 commitlint를 사용하여 git commit시에 prefix를 쉽게 적용하고, commit 메세지에 대한 검사를 진행하기 위해 적용하는 것을 선호합니다.

npx husky-init && npm install
npm install --save-dev @commitlint/cli @commitlint/config-conventional commitizen

npx commitizen init cz-conventional-changelog --save-dev --save-exact
npx husky add .husky/commit-msg 'npx --no-install commitlint --edit $1'
npx husky add .husky/prepare-commit-msg 'exec < /dev/tty && node_modules/.bin/cz --hook || true'
//commitlint.config.js
module.exports = { extends: ['@commitlint/config-conventional'] }

설정이 완료되면 터미널에 git commit명령어를 입력시 prefix 선택과 commit의 제목을 입력 할 수 있습니다.

test library, jest dom eslint 설치

cra로 설치 시 기본적인 세팅은 적용되어 있지만, 좀 더 깔끔한 테스트 코드 작성을 위해 설치하는 것이 좋은 것 같습니다.

npm install --save-dev eslint-plugin-testing-library
npm install --save-dev eslint-plugin-jest-dom
// .eslintrc.json
{
  "plugins": ["testing-library", "jest-dom"],
  "extends": [
    "react-app",
    "react-app/jest",
    "plugin:testing-library/react",
    "plugin:jest-dom/recommended"
  ]
}

eslint를 설정 하면 왼쪽 코드를 오른쪽 코드로 자동 수정이 가능

typescript

npm install --save typescript @types/node @types/react @types/react-dom @types/jest
// tsconfig.json
{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",
    "strictNullChecks": false
  },
  "include": ["src"]
}

react 18버전이 나오면서 cra 사용시 react와 관련된 type 라이브러리간에 싱크가 안맞는 경우가 있습니다. 이럴 때 위에 적혀있는 라이브러리에 대한 업데이트가 필요할 수 있습니다. 

 

Adding TypeScript | Create React App

Note: this feature is available with react-scripts@2.1.0 and higher.

create-react-app.dev

 

반응형
저작자표시 비영리 변경금지 (새창열림)

'WEB > React' 카테고리의 다른 글

React에서 JWT를 이용하여 로그인 구현하기  (1) 2022.08.05
React 18 버전으로 개발하면서 만난 문제들  (0) 2022.04.13
react 18버전에서 달라지는 batching  (0) 2022.04.04
react 컴포넌트가 unmount 된 후 setState가 실행되는 문제 해결 방법  (0) 2021.07.12
폴더 안의 파일을 모두 import 하는 방법  (0) 2021.02.16
'WEB/React' 카테고리의 다른 글
  • React에서 JWT를 이용하여 로그인 구현하기
  • React 18 버전으로 개발하면서 만난 문제들
  • react 18버전에서 달라지는 batching
  • react 컴포넌트가 unmount 된 후 setState가 실행되는 문제 해결 방법
vitnal
vitnal
4년차 프론트엔드 개발자 입니다. 이 블로그는 기록하고 싶은 내용을 저장하기 위해 사용하고 있습니다. 정제되지 않은 내용이 있을 수 있는 점 양해 부탁드립니다.
  • vitnal
    vitnal 아카이브
    vitnal
  • 전체
    오늘
    어제
    • 분류 전체보기 (148) N
      • AI (0)
      • WEB (76)
        • React (21)
        • Nextjs (17)
        • JavaScript (16)
        • React Native (5)
        • HTML & CSS (7)
      • CS (3)
      • Git (15)
      • Dev Tools (23)
      • Deploy (12)
      • Tech Memo (11) N
      • Retrospect (7)
  • 반응형
  • hELLO· Designed By정상우.v4.10.5
vitnal
React 초기 프로젝트 세팅 (eslint, husky etc..)
상단으로

티스토리툴바