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

매일 치는 Bun 명령

~12 min · bun, commands, workflow

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

Bun 명령은 기존 npm과 pnpm 사용자가 바로 적응할 수 있도록 의도적으로 비슷하게 만들었어. 차이는 Bun이 자체 도구를 더한 부분에서 나타나.

bun add <pkg>는 런타임 의존성을, bun add -d <pkg>는 개발 의존성을 추가해. bun remove <pkg>는 제거하고 bun installbun.lock에서 모든 의존성을 설치해. CI에서는 bun install --frozen-lockfile을 써.

bun run <script>는 package.json 스크립트를 실행하고, Bun 내장 명령과 이름이 겹치지 않으면 run을 생략할 수도 있어. 주의할 점은 bun build가 package.json의 빌드 스크립트가 아니라 Bun 자체 bundler를 호출한다는 거야. bun index.ts는 TypeScript 파일을 직접 실행하고, bun test는 Jest 호환 API를 가진 빠른 내장 테스트 실행기를 시작해.

bun build는 bundler이고 bunx <tool>은 Bun의 npx야. bun pm <subcommand>는 패키지 관리자 운영 명령을 모아 두었어. 예를 들어 bun pm migrate는 yarn.lock이나 pnpm-lock.yaml을 bun.lock으로 바꿔. v1.3에서 추가된 bun audit은 보안 취약점을 검사하고, bun outdated는 registry의 최신 버전보다 뒤처진 패키지를 보여 줘.

Code

npm과 닮은 빠른 Bun 명령·bash
# 추가 / 제거
bun add express
bun add -d vitest typescript
bun remove express

# Install
bun install
bun install --frozen-lockfile    # CI 모드

# 스크립트 실행
bun run build                    # 명시적
bun build                        # Bun 의 bundler — 다른 명령
bun test                         # 빌트인 test runner
bun dev                          # 'bun run dev' 의 shorthand

# TS 파일 직접 실행 — 컴파일 없음
bun index.ts
bun src/server.tsx
이전과 보안 검사·bash
# yarn 또는 pnpm 에서 Bun 으로 마이그레이션
bun pm migrate

# 뭐가 outdated?
bun outdated

# 보안 스캔
bun audit

# install 없이 도구 실행
bunx create-vite my-app
esbuild급 속도의 Bun 내장 bundler·bash
# TypeScript entry point bundle
bun build ./src/index.ts --outdir ./dist --minify

# 브라우저용 bundle
bun build ./src/index.tsx --outdir ./dist --target browser

# Watch 모드
bun build ./src/index.ts --outdir ./dist --watch

External links

Exercise

실제 npm 프로젝트에서 'bun pm migrate'를 실행하고 'time bun install'로 설치 시간을 재. 이전의 'time npm install' 결과와 비교해 봐. 숫자 차이만으로도 다음 새 프로젝트에서 Bun을 시험할 이유가 충분할 수 있어.

Progress

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

댓글 0

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

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