CRA with Typescript 프로젝트 세팅

Seungrok Yoon (Lethe)·2023년 8월 23일
1

[FE] 프로젝트 세팅

목록 보기
6/6

npx create-react-app@latest .

CRA with ts
react-router-dom
Axios

eslint
prettier
https://github.com/jsx-eslint/eslint-plugin-react

npx create-react-app@latest . --template typescript

npm install react-router-dom
npm install axios
npm install react-router-dom
npm install styled-components

npm install --save-dev eslint
npm install --save-dev eslint-plugin-react
npm install --save-dev --save-exact prettier
npm install --save-dev eslint-config-prettier
npm install --save-dev eslint-plugin-react-hooks 
npm install --save-dev eslint-plugin-unused-imports
npm install eslint-plugin-unused-imports --save-dev --legacy-peer-deps <= CRA와 디펜던시 충돌나서 준 옵션

//npm install --save-dev @typescript-eslint/parser @typescript-eslint/eslint-plugin CRA에 포함되어 있음

https://github.com/jsx-eslint/eslint-plugin-react/blob/HEAD/docs/rules/jsx-sort-props.md
https://ru.legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html#eslint

인증다루기
https://github.com/remix-run/react-router/tree/dev/examples/auth-router-provider

.eslintrc.js

module.exports = {
  settings: {
    react: {
      version: 'detect',
    },
  },
  env: {
    browser: true,
    es2021: true,
    node: true,
  },
  extends: [
    'eslint:recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:react/recommended',
    'plugin:react/jsx-runtime',
    'plugin:react-hooks/recommended',
    'prettier',
  ],

  parser: '@typescript-eslint/parser',
  parserOptions: {
    ecmaVersion: 'latest',
    sourceType: 'module',
    ecmaFeatures: {
      jsx: true,
    },
  },
  plugins: ['@typescript-eslint', 'react', 'unused-imports'],
  rules: {
    'react/react-in-jsx-scope': 'off',
    'react/jsx-uses-react': 'off',
    'no-unused-vars': 'off',
    '@typescript-eslint/no-unused-vars': 'error',
    'react/jsx-uses-vars': 'error', // var로 JSX할당하면 에러
    'react/button-has-type': 'error', //button에 타입지정안하면 에러
    'react/jsx-sort-props': [
      //JSX prop을 정렬해줌
      'warn',
      {
        callbacksLast: true,
        shorthandFirst: true,
        ignoreCase: true,
        reservedFirst: true,
      },
    ],
    'react-hooks/exhaustive-deps': 'warn',
    'unused-imports/no-unused-imports': 'error', // 사용하지 않는 import 문을 지워줌
  },
}

.prettierrc.json

{
  "trailingComma": "es5",
  "tabWidth": 2,
  "printWidth": 100,
  "semi": false,
  "singleQuote": true,
  "jsxSingleQuote": false
}

husky 자동화

https://typicode.github.io/husky/getting-started.html

profile
안녕하세요 개발자 윤승록입니다. 내 성장을 가시적으로 기록하기 위해 블로그를 운영중입니다.

0개의 댓글