리액트 프로젝트를 시작하는데 필요한 개발 환경을 세팅 해주는 도구(toolchain)
npx create-react-app my-project
npm
으로 global
하게 설치하게되면 여러가지 문제가 생깁니다npx
를 사용하면 이 문제를 해결할 수 있습니다. npx는 최신 버전에 해당하는 패키지를 설치하여 실행하고, 실행된 이후에 해당 패키지를 제거cd my-project
npm start
1. node.modules
2. public 폴더
<div id="root"></div>
fetch('http://localhost:3002/data/data.json')
이런 방식으로 fetch를 통하여 데이터를 받아올 수 있음3. src 폴더
index.js
ReactDOM.render( <App /> , document.getElementById('root'))
App.js
<Routes />
컴포넌트가 최상위 컴포넌트로 그 자리에 위치하게 된다.(추가)components - 공통 컴포넌트 관리
(추가)pages - 페이지 단위의 컴포넌트 폴더로 구성
(추가)styles 폴더
reset.scss
- css 초기화commom.scss
- 공통으로 사용하는 css 속성 정의 (ex. font-family, theme color)참고) components vs. pages
1. package.json
CRA 기본 패키지 외 추가로 설치된 라이브러리/패키지 정보(종류, 버전)가 기록되는 파일
모든 프로젝트마다 package.json 하나씩 존재
"dependencies"
node.modules
폴더에 존재^
를 붙이게 되면 package manaager는 새로운 버전이 배포 되었는지 체크새로운 Library(package) 설치 시
yarn과 npm 차이
package.json
에 버전을 명시하고 의존성은 추적 관리npm shrinkwrap
커맨드로 생성"scripts"
npm run start
.package.json
과 package-lock.json
차이
package-lock.json
은 개발자들이 동일한 node_module
트리를 생성해서 같은 의존성을 설치할 수 있도록 보장해주는 고마운 녀석2. .gitignore
.gitignore
파일에 github 에 올리고 싶지 않은 폴더와 파일을 작성할 수 있다.push
를 해도 .gitignore
파일에 작성된 폴더와 파일은 올라가지 않는다프로젝트 만들기
npx create-react-app my-app --template typescript
Type script용 모듈들 다운로드
npm install --save typescript @types/node @types/react @types/react-dom @types/jest
ESLint는 ES + Lint
npm i --save-dev @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-react
루트폴더에 .eslintrc.json 을 만들고 아래 코드를 저장
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"plugin:react/recommended", // Uses the recommended rules from @eslint-plugin-react
"plugin:@typescript-eslint/recommended"
],
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"rules": {
"semi": 2
},
"settings": {
"react": {
"version": "detect"
}
}
}
prettier: 코드 포매팅을 자동으로 해주는 라이브러리
npm i --save-dev eslint-config-prettier eslint-plugin-prettier
루트 폴더에 .prettierrc 파일 만들고
{
"singleQuote": true,
"semi": true,
"useTabs": false,
"tabWidth": 2,
"trailingComma": "all",
"printWidth": 80
}
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"plugin:react/recommended", // Uses the recommended rules from @eslint-plugin-react
"plugin:@typescript-eslint/recommended",
"prettier/@typescript-eslint",
"plugin:prettier/recommended"
],
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"rules": {
"semi": 2,
"@typescript-eslint/explicit-function-return-type": [
"warn",
{ "allowTypedFunctionExpressions": true }
]
},
"settings": {
"react": {
"version": "detect"
}
}
}