๋ฐ˜์‘ํ˜•

ํ”„๋กœ์ ํŠธ ํ™˜๊ฒฝ์„ค์ •

๐Ÿ€ ES Lint / Prettier ์„ค์ •

  1. eslint, prettier ํŒจํ‚ค์ง€ ์„ค์น˜
    • yarn add -D eslint prettier eslint-plugin-prettier eslint-config-prettier eslint-plugin-react eslint-config-react-app
  2. 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"
          }
      โ€‹
  3. setting.json ํŒŒ์ผ์— ์•„๋ž˜ ์ฝ”๋“œ ์ถ”๊ฐ€
    • Ctrl + Shift + P๋ฅผ ๋ˆŒ๋Ÿฌ ๋ช…๋ น ํŒ”๋ ˆํŠธ๋ฅผ ์—ด๊ธฐ → "Preferences: Open Settings (JSON)"์„ ์ž…๋ ฅํ•˜๊ณ  ์„ ํƒ
      // ์ˆ˜์ • ํ›„ ์ €์žฅํ•  ๋•Œ eslint๋กœ autofix ์‹คํ–‰
      "editor.codeActionsOnSave": {
        "source.fixAll.eslint": "true"
      },
      // ํŒŒ์ผ์˜ ์ค„ ๋(Line Ending) ํ˜•์‹์„ ์ง€์ •. ์•ž์œผ๋กœ ์ƒ์„ฑ๋˜๋Š” ํŒŒ์ผ๋“ค์€ lf(mac)๋กœ ์ƒ์„ฑ๋จ
      "files.eol":"\\n",
    
    โœ… ํŒŒ์ผ์˜ ์ค„ ๋ ํ˜•์‹ :: mac vs window
    "files.eol": "\n": ํŒŒ์ผ์˜ ์ค„ ๋์„ ์œ ๋‹‰์Šค/๋ฆฌ๋ˆ…์Šค ์Šคํƒ€์ผ์ธ LF (Line Feed) ํ˜•์‹์œผ๋กœ ์ง€์ •
    "files.eol": "\r\n" : ํŒŒ์ผ์˜ ์ค„ ๋์„ Windows ์‹œ์Šคํ…œ์˜ ๊ธฐ๋ณธ ํ˜•์‹์ธ CRLF ํ˜•์‹์œผ๋กœ ์ง€์ •

  4. vscode์— ์ ์šฉ
    yarn dlx @yarnpkg/sdks vscode
    
  5. prettier์—์„œ ์„ธ๋ฏธ์ฝœ๋ก  ์ œ๊ฑฐ ์„ค์ •ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— package.json์— ์•„๋ž˜ ์ฝ”๋“œ ์ถ”๊ฐ€
    //package.json
        "lint": "eslint \\"src/**/*/{js,jsx,ts,tsx}\\"",
        "lint:fix": "eslint \\"src/**/*/{js,jsx,ts,tsx}\\""
    
    
    • ์ ์šฉ
    yarn lint:fix
    
  6. 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')}> ์ด๋Ÿฐ์‹์œผ๋กœ ์‚ฌ์šฉ!
๋ฐ˜์‘ํ˜•

+ Recent posts