리액트와 타입스크립트로 프로젝트를 시작할 때, 사용하는 세팅에 대해 간단하게 정리합니다.
npx create-react-app my-app --template=typescript
// tsconfig.json
{
"compilerOptions": {
...
"jsx": "react-jsx",
"baseUrl": "src"
}
}
npm install --save @emotion/react @emotion/styled
npm install --save-dev prettier eslint
// .prettier.js
module.exports = {
singleQuote: true,
trailingComma: 'all',
printWidth: 100,
}
npx eslint --init
// .eslint.js
...
"rules": {
'react/react-in-jsx-scope': 'off',
}
.src/App.tsx 파일 수정
import React from 'react';
제거
// package.json
...
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"format": "prettier --check ./src",
"format:fix": "prettier --write ./src",
"lint": "eslint ./src",
"lint:fix": "eslint --fix ./src"
},
npm run format:fix
npm run lint:fix
npm run format
npm run lint
npm start
프로젝트는 그 목적에 따라서 얼마든지 세팅 값이 달라질 수 있습니다. 다만 일반적으로 프로젝트를 시작할 때, 위와 같이 설정 해놓으면 문제 없이 시작할 수 있습니다.
좋은 글 감사합니다 :)