๋ฐ์ํ
ํ๋ก์ ํธ ํ๊ฒฝ์ค์
๐ ES Lint / Prettier ์ค์
- eslint, prettier ํจํค์ง ์ค์น
- yarn add -D eslint prettier eslint-plugin-prettier eslint-config-prettier eslint-plugin-react eslint-config-react-app
- Config ์ค์ ๋ถ๋ฆฌ
- package.json์ "eslintConfig”๋ถ๋ถ์ ๋ณ๋์ .eslintrc.jsonํ์ผ๋ก ๋ถ๋ฆฌ ํ ์ถ๊ฐ ์ค์ ์์ฑ
//.eslintrc.json { "extends": [ "react-app", "react-app/jest", "plugin:prettier/recommended" ], "plugins":["prettier"], "rules":{ "prettier/prettier":"error" } } โ
- .prettierrc ํ์ผ ์์ฑ
//prettierrc { "useTabs": false, "printWidth": 80, "tabWidth": 2, "singleQuote": true, "trailingComma": "all", "endOfLine": "lf", // ํ์ผ์ ์ค ๋(Line Ending) ํ์์ ์ง์ "semi": false, "arrowParens": "always" } โ
- package.json์ "eslintConfig”๋ถ๋ถ์ ๋ณ๋์ .eslintrc.jsonํ์ผ๋ก ๋ถ๋ฆฌ ํ ์ถ๊ฐ ์ค์ ์์ฑ
- setting.json ํ์ผ์ ์๋ ์ฝ๋ ์ถ๊ฐ
- Ctrl + Shift + P๋ฅผ ๋๋ฌ ๋ช ๋ น ํ๋ ํธ๋ฅผ ์ด๊ธฐ → "Preferences: Open Settings (JSON)"์ ์ ๋ ฅํ๊ณ ์ ํ
โ ํ์ผ์ ์ค ๋ ํ์ :: mac vs window// ์์ ํ ์ ์ฅํ ๋ eslint๋ก autofix ์คํ "editor.codeActionsOnSave": { "source.fixAll.eslint": "true" }, // ํ์ผ์ ์ค ๋(Line Ending) ํ์์ ์ง์ . ์์ผ๋ก ์์ฑ๋๋ ํ์ผ๋ค์ lf(mac)๋ก ์์ฑ๋จ "files.eol":"\\n",
"files.eol": "\n": ํ์ผ์ ์ค ๋์ ์ ๋์ค/๋ฆฌ๋ ์ค ์คํ์ผ์ธ LF (Line Feed) ํ์์ผ๋ก ์ง์
"files.eol": "\r\n" : ํ์ผ์ ์ค ๋์ Windows ์์คํ ์ ๊ธฐ๋ณธ ํ์์ธ CRLF ํ์์ผ๋ก ์ง์ - vscode์ ์ ์ฉ
yarn dlx @yarnpkg/sdks vscode
- prettier์์ ์ธ๋ฏธ์ฝ๋ก ์ ๊ฑฐ ์ค์ ํ๊ธฐ ๋๋ฌธ์ package.json์ ์๋ ์ฝ๋ ์ถ๊ฐ
//package.json "lint": "eslint \\"src/**/*/{js,jsx,ts,tsx}\\"", "lint:fix": "eslint \\"src/**/*/{js,jsx,ts,tsx}\\""
- ์ ์ฉ
yarn lint:fix
- Craco Alias ์ค์
- ์ค์น
yarn add -D @craco/craco craco-alias
- tsconfig.paths.json ์ ์
// tsconfig.paths.json { "compilerOptions":{ "baseUrl":".", "paths":{ "@/*": ["src/*"], "@components/*":["src/components/*"] } } }
- craco.config.js ์ ์
// craco.config.js module.exports = { plugins: [ { plugin: CracoAlias, options: { source: 'tsconfig', tsConfigPath: 'tsconfig.paths.json', }, }, ], }
- Tsconfig์ tsconfig.paths.json extends ์ํค๊ธฐ
// tsconfig.json { "extends": "./tsconfig.paths.json", "compilerOptions": { "target": "es5", "lib": ["dom", "dom.iterable", "esnext"], "allowJs": true, "skipLibCheck": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true, "strict": true, "forceConsistentCasingInFileNames": true, "noFallthroughCasesInSwitch": true, "module": "esnext", "moduleResolution": "node", "resolveJsonModule": true, "isolatedModules": true, "noEmit": true, "jsx": "react-jsx" }, "include": ["src", "tsconfig.paths.json"] } โ
- ์ค์น
๐ scss ์ค์
yarn add classnames sass
- global.scss ์์ฑ
- App.module.scss ์์ฑ
- src\App.tsx
import classNames from 'classnames/bind'
import styles from './App.module.scss'
const cx = classNames.bind(styles)
// <div className={cx('container')}> ์ด๋ฐ์์ผ๋ก ์ฌ์ฉ!
๋ฐ์ํ