본문 바로가기
C.W.K.
Stream
Lesson 03 of 05 · published

매일 치는 Yarn Berry 명령

~11 min · yarn, commands, workflow

Level 0입문자
0 XP0/55 lessons0/16 achievements
0/80 XP to next level80 XP to go0% complete

Berry 명령은 npm과 pnpm에 가깝지만 몇몇 동사의 이름을 의도적으로 바꿨어. 작은 차이만 익히면 기존 습관을 그대로 옮길 수 있어.

yarn add <pkg>는 런타임 의존성을 추가하고, yarn add --dev <pkg>는 개발 의존성을 추가해. 여기서는 -D가 아니라 --dev를 쓴다는 점을 기억해. yarn remove <pkg>는 제거하고, yarn install은 모든 의존성을 설치해. yarn install --immutable은 Berry에서 npm ci에 해당하며 lockfile이 바뀌어야 한다면 실패하므로 CI에 알맞아.

yarn up <pkg>는 패키지를 업그레이드해. npm이나 pnpm의 upgrade 대신 Berry가 택한 동사야. yarn upgrade-interactive는 올릴 패키지를 고르는 터미널 화면을 열어.

yarn dlx <tool>는 Berry의 npx로, 설치 없이 도구를 실행해. yarn workspaces foreach run build는 모든 workspace에서 스크립트를 실행하고 yarn workspaces list는 workspace 목록을 보여 줘.

yarn node script.js는 PnP 런타임을 주입한 Node로 스크립트를 실행해. PnP 코드가 별도 설정 없이 일반 node에서 동작하지 않을 수 있어서 필요해. .yarnrc.yml에 nodeLinker: node-modules를 설정해 PnP를 끄면 일반 node도 그대로 작동해.

Code

매일 Berry 명령·bash
# 추가 / 제거
yarn add express
yarn add --dev vitest typescript
yarn remove express

# Install
yarn install
yarn install --immutable    # CI 모드 (npm ci 등가물)

# 스크립트 실행
yarn build
yarn test
yarn dev

# install 없이 도구 실행
yarn dlx create-vite my-app

# 인터랙티브 업그레이드
yarn upgrade-interactive
일급 monorepo 기능인 workspaces·bash
# Berry monorepo 에서 (workspaces 는 package.json 에 선언)
yarn workspaces list

# 모든 workspace 에 'build' 실행
yarn workspaces foreach run build

# 'web' workspace 에서만 'dev' 실행
yarn workspace web run dev

# 특정 workspace 에 dep 추가
yarn workspace web add react

External links

Exercise

Berry 프로젝트에서 'yarn dlx create-vite my-app'을 실행하고 이어서 'cd my-app && yarn install --immutable'을 실행해. .yarn/ 디렉터리에서 cache와 releases, PnP가 켜져 있다면 unplugged 폴더까지 살펴봐. 각 디렉터리가 맡는 역할을 문서에서 확인해.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.