아래의 모든 과정을 통해 만든 boilerplate입니다!
바쁘신 분은 여기서 가져가세요~😊
$ npx create-react-app [project name] --template typescript
// ex
$ npx create-react-app react-ts-boilerplate --template typescript
// src/index.tsx
import React from 'react'
import * as ReactDOM from 'react-dom/client'
import './index.css'
import App from './App'
import reportWebVitals from './reportWebVitals'
const container = document.getElementById('root') as HTMLElement
const root = ReactDOM.createRoot(container)
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
)
reportWebVitals()
이 설정을 마치면 아래와 같은 경로일 경우 어떤 파일에서는 logo.svg
에 접근하는 방식은 @/assets/images/logo.svg
가 된다.
src
ㄴ assets
ㄴ images
- logo.svg
- App.tsx
- index.tsx
{
"compilerOptions": {
...
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
}
}
$ yarn add -D @craco/craco
craco.config.js
파일 생성// in craco.config.js
const path = require('path')
module.exports = {
webpack: {
alias: {
'@': path.resolve('src/'),
},
},
}
// in package json
{
...
"scripts": {
"start": "craco start",
...
}
...
}
$ yarn add react-router-dom
// 기본 eslint, prettier
$ yarn add -D eslint prettier
// eslint와 prettier가 충돌하지 않게 하기 위한 연결
$ yarn add -D eslint-config-prettier eslint-plugin-prettier
// typescript에 필요한 eslint
$ yarn add -D @typescript-eslint/parser @typescript-eslint/eslint-plugin
.eslintrc
파일 생성// .eslintrc
{
"env": { "node": true, "browser": true },
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "prettier"],
"extends": [
"eslint:recommended",
"plugin:prettier/recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:@typescript-eslint/recommended"
]
}
.prettierrc
파일 생성{
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
"vueIndentScriptAndStyle": true,
"endOfLine": "auto",
"tabWidth": 2,
"arrowParens": "avoid",
"bracketSpacing": true,
"printWidth": 80,
"useTabs": false
}
저장 시 자동 수정이 안된다면, vscode를 재실행!
$ yarn add recoil
// src/index.tsx
import { RecoilRoot } from 'recoil'
...
root.render(
<React.StrictMode>
<RecoilRoot>
<App />
</RecoilRoot>
</React.StrictMode>
)
...
$ yarn add @emotion/react
// styled component 사용할 경우 설치
$ yarn add @emotion/styled