기록

프로젝트 초기 설정 - Vite + React + TypeScript + MobX + React Query

프로젝트 초기 설정 · 1 / 3편
  1. 프로젝트 초기 설정 - Vite + React + TypeScript + MobX + React Query
  2. 프로젝트 Import 경로 설정 (절대경로, 상대경로) #1
  3. 프로젝트 경로 설정 (Vite, TypeScript, ES-Lint) #2
  1. Vite 이용, React + TypeScript 설처

  2. ESLint 설치

  3. Prettier 설치

  4. Vite + TypeScript Install

npm create vite@latest front-boilerplate-vite -- --template react-ts

2. ESLint Install

npx eslint --init

.eslintrc.cjs 가 생성 되었을 것 입니다.

2-1. 하단에 아래와 같이 코드를 추가해 React Version을 맞춰 줍니다.

2-2. touch .eslintignore 파일 생성 후 작성
eslint설정을 적용하지 않을 파일을 설정 하는 곳으로, 각 project 환경과 설정에 따라 달라 집니다.

3. Prettier Install

npm install --save-dev  prettier
touch .prettierrc

3-1. Prettier 기본 환경 설정 예시

{
  "endOfLine": "lf",
  "printWidth": 80,
  "tabWidth": 2,
  "trailingComma": "es5",
  "singleQuote": true,
  "jsxSingleQuote": true,
  "semi": true
}

3-2 .prettierignore 파일 생성 후 작성

  1. ESLint 와 Prettier 충돌 방지
    ESLint에 코드 포맷 기능과 Prettier의 코드 포맷 기능이 충돌 되지 않도록 설정 합니다.
npm install --dev eslint-config-prettier

4-1 .eslintrc.cjs 파일 수정

  1. ESLint 실행
./node_modules/.bin/eslint src/App.tsx

오류 1번

수정 project: [ './tsconfig.json'] 추가

오류 2번

오류를 자세히 보면, 우측에 어떠한 룰과 연관 되어 있는지 표기 해줍니다.

오류 3.

...blank 라고 되어 있는 문제는, 아래와 같이 개선 합니다. (참고 사이트 : https://beomsoo.me/issue/Issue-4/_)

App.tsx -> target="_blank" 에 rel="noopener noreferrer" 추가

전체 ESLint 설정 파일

module.exports = {
  env: {
    browser: true,
    es2021: true
  },
  extends: [
    'plugin:react/recommended',
    'standard-with-typescript',
    'prettier'
  ],
  overrides: [
  ],
  parserOptions: {
    ecmaVersion: 'latest',
    sourceType: 'module',
    project: ['./tsconfig.json'],
  },
  plugins: [
    'react'
  ],
  rules: {
    'react/react-in-jsx-scope': 'off',
    '@typescript-eslint/explicit-function-return-type': 'off',
    '@typescript-eslint/no-confusing-void-expression': [
      'error',
      {
        ignoreArrowShorthand: true,
        ignoreVoidOperator: true,
      },
    ],
  },
  settings:{
    react : {
      version: '18.2.0'
    }
  }
}

댓글

이름만 적고 남길 수 있어요