๋ฐ˜์‘ํ˜•

๐Ÿ‘ฟYarn Berry ํ”„๋กœ์ ํŠธ ํ™˜๊ฒฝ ์„ค์ • ์ค‘ .yarn/cache ์ƒ์„ฑ๋˜์ง€ ์•Š๋Š” ๋ฌธ์ œ

Yarn Berry ํ”„๋กœ์ ํŠธ ํ™˜๊ฒฝ ์„ค์ • ์ค‘ .yarn/cache ์ƒ์„ฑ๋˜์ง€ ์•Š๋Š” ๋ฌธ์ œ. yarn install์„ ์•„๋ฌด๋ฆฌ ์‹œ๋„ํ•ด๋„ ์บ์‹œํด๋”๊ฐ€ ์ƒ์„ฑ๋˜์ง€ ์•Š์Œ..

๐Ÿง ์—๋Ÿฌ ์›์ธ

  • ์ด์ „์—๋Š” enableGlobalCache์˜ ๊ธฐ๋ณธ๊ฐ’์ด false์˜€๊ธฐ ๋•Œ๋ฌธ์—, ๊ฐ ํ”„๋กœ์ ํŠธ๊ฐ€ ๋กœ์ปฌ .yarn/cache ํด๋”์— ์˜์กด์„ฑ์„ ์ €์žฅํ•˜๋„๋ก ๋˜์–ด ์žˆ์—ˆ๋‹ค.
  • ํ•˜์ง€๋งŒ ์ตœ๊ทผ ์—…๋ฐ์ดํŠธ์—์„œ enableGlobalCache์˜ ๊ธฐ๋ณธ๊ฐ’์„ true๋กœ ๋ณ€๊ฒฝํ•˜์—ฌ, ์ „์—ญ ์บ์‹œ ์‚ฌ์šฉ์„ ๊ธฐ๋ณธ ์„ค์ •์œผ๋กœ ์ ์šฉํ•˜๊ฒŒ ๋˜์—ˆ๋‹ค.
  • ๋”ฐ๋ผ์„œ Yarn์˜ ์ตœ์‹  ๋ฒ„์ „์—์„œ๋Š” enableGlobalCache: false ์„ค์ •์„ .yarnrc.yml์— ์ง์ ‘ ์ถ”๊ฐ€ํ•ด์•ผ๋งŒ ๋กœ์ปฌ ์บ์‹œ๊ฐ€ ์ƒ์„ฑ๋œ๋‹ค. ์„ค์ • ํŒŒ์ผ์— ํ•ด๋‹น ์˜ต์…˜์„ ์ง์ ‘ ์ถ”๊ฐ€ํ•˜์ง€ ์•Š์œผ๋ฉด, Yarn์€ ์ „์—ญ ์บ์‹œ๋ฅผ ์‚ฌ์šฉํ•˜๋ฏ€๋กœ .yarn/cache ํด๋”๊ฐ€ ์ƒ์„ฑ๋˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒ ํ–ˆ๋˜ ๊ฒƒ!

โœจ ์—๋Ÿฌ ํ•ด๊ฒฐ

  • .yarnrc.yml ํŒŒ์ผ์— enableGlobalCache: false ์„ค์ • ์ถ”๊ฐ€
    //.yarnrc.yml 
    nodeLinker: pnp
    enableGlobalCache: false
    โ€‹
  • ์„ค์ • ๋ณ€๊ฒฝ ํ›„ ํ”„๋กœ์ ํŠธ ์˜์กด์„ฑ ์žฌ์„ค์น˜
    yarn install

๋“œ๋””์–ด cacheํŒŒ์ผ์ด ์ƒ์„ฑ๋˜์—ˆ๋‹ค!!

๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

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

๐Ÿ€ 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')}> ์ด๋Ÿฐ์‹์œผ๋กœ ์‚ฌ์šฉ!
๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

๐Ÿ€ 1. ํ”„๋กœ์ ํŠธ ์ƒ์„ฑํ•˜๊ธฐ

  • yarn ์„ค์น˜
npm install -g yarn
  • Create React App ๊ธฐ๋ฐ˜ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ
yarn create react-app wedding --template typescript

๐Ÿ€ 2. Yarn Berry(PnP) ์„ค์ •

  1. node_modules ํด๋” ์‚ญ์ œ
  2. berry ๋ฒ„์ „ ์„ค์ • ::  yarn set version berry
    yarn set version berry
  3. root ๊ฒฝ๋กœ์— .yarnrc.ymlํŒŒ์ผ ์ƒ์„ฑ
    //.yarnrc.yml ํŒŒ์ผ์— pnp ์„ค์ •ํ•˜๊ธฐ (node_modules ๋Œ€์‹  pnp๋ฐฉ์‹ ์‚ฌ์šฉ!)
    nodeLinker: pnp
    
  4. yarn install
    yarn install
    

ํ™•์žฅ ํ”„๋กœ๊ทธ๋žจ ZipFS ์„ค์น˜


Yarn Berry์—์„œ TypeScript๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ zipfs ํ™•์žฅ ๊ธฐ๋Šฅ์ด ํ•„์š”ํ•œ ์ด์œ ๋Š” Yarn์˜ Plug'n'Play(PnP) ๋ฐฉ์‹ ๋•Œ๋ฌธ์ด๋‹ค. Yarn Berry๋Š” node_modules ํด๋” ์—†์ด .zip ํŒŒ์ผ์„ ํ†ตํ•ด ์˜์กด์„ฑ์„ ๊ด€๋ฆฌํ•˜๋Š”๋ฐ, ์ด๋•Œ ํŒŒ์ผ ์‹œ์Šคํ…œ์„ .zip ํ˜•์‹์œผ๋กœ ์ €์žฅํ•˜๊ณ  ๋ถˆ๋Ÿฌ์˜ค๋Š” ๊ณผ์ •์—์„œ zipfs๊ฐ€ ํ•„์š”ํ•˜๋‹ค.๋”ฐ๋ผ์„œ zipfs๋ฅผ ์„ค์น˜ํ•˜๋ฉด, Yarn Berry์˜ PnP ๋ฐฉ์‹๊ณผ TypeScript ํ™˜๊ฒฝ ๊ฐ„์˜ ํ˜ธํ™˜์„ฑ์„ ๋†’์—ฌ์ค€๋‹ค. zipfs ํ™•์žฅ ๊ธฐ๋Šฅ์€ .zip ํŒŒ์ผ๋กœ ์ €์žฅ๋œ ํŒจํ‚ค์ง€๋“ค์„ ํŒŒ์ผ ์‹œ์Šคํ…œ์ฒ˜๋Ÿผ ์ฝ์„ ์ˆ˜ ์žˆ๋„๋ก ์ง€์›ํ•˜์—ฌ, PnP ํ™˜๊ฒฝ์—์„œ TypeScript๋‚˜ ๊ธฐํƒ€ ํˆด์ด ์ •์ƒ์ ์œผ๋กœ ํŒจํ‚ค์ง€ ํŒŒ์ผ์„ ํƒ์ƒ‰ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•œ๋‹ค.

 

6. Yarn Berry์˜ Plug'n'Play(PnP) ๋ฐฉ์‹๊ณผ VSCode์˜ ํ†ตํ•ฉ ์„ค์ •

yarn dlx @yarnpkg/sdks vscode
๐Ÿ”ฅ๐Ÿ‘ฟ ์ฃผ์˜!!
๋ช…๋ น ํŒ”๋ ˆํŠธ(Ctrl+Shift+P)๋ฅผ ์—ด๊ณ  TypeScript: Restart TS Server"๋ฅผ ์„ ํƒ → "Use Workspace Version”๋ถ€๋ชจ ํด๋”๊ฐ€ ์•„๋‹Œ ํ”„๋กœ์ ํŠธ ํด๋” ์ž์ฒด์—์„œ VSCode๋ฅผ ์—ด์–ด์•ผ ํ•œ๋‹ค!!!! vscode๊ฐ€ ๋ถ€๋ชจํด๋”๋กœ ์—ด๋ ค์žˆ๋‹ค๋ฉด Use Workspace Version๊ฐ€ ๋ณด์ด์ง€ ์•Š์Œ...
์ฐธ๊ณ :: https://github.com/yarnpkg/berry/issues/4788

๐Ÿ€ 3. typescript ์„ค์ •

์›Œํฌ์ŠคํŽ˜์ด์Šค ๋ฒ„์ „์— ๋งž๋Š” ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ๋ฒ„์ „์„ ์‚ฌ์šฉํ•˜๋„๋ก ํ—ˆ์šฉํ•ด์ฃผ๊ธฐ

๐Ÿ€ 4. .gitignore์— ์ถ”๊ฐ€

# yarn zero install
.yarn/*
!.yarn/cache
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

# ์ฐธ๊ณ ::  https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored

 

Questions & Answers | Yarn

A list of answers to commonly asked questions.

yarnpkg.com

 

๐Ÿ€ 5. App.test.tsx์˜ ํƒ€์ž…์—๋Ÿฌ ์ œ๊ฑฐํ•˜๊ธฐ

ํƒ€์ž…์—๋Ÿฌ ์™•์ฐฝ

yarn remove @testing-library/jest-dom
yarn add -D @types/testing-library__jest-dom @testing-library/jest-dom

๐Ÿ€ 6. yarn start!!!!!!!!!!!!!!!!!!!!!!!

yarn start

 

๋ฐ˜์‘ํ˜•

+ Recent posts