Index – Turborepo

Node.js

# Node.js 버전 확인
➜ node -v
v20.9.0

# v20.9.0 가 설치되어 있지 않다면
➜ nvm install 20.9.0

# v20.9.0 를 사용하고 있지 않다면
➜ nvm use 20.9.0

# Node.js 버전 다시 확인
➜ node -v
v20.9.0

npm

# npm 버전 확인
➜ npm -v
10.2.1

# 최신 버전 npm 으로 업그레이드 
➜ npm i [email protected] -g

# npm 버전 다시 확인
➜ npm -v
10.2.1

pnpm

# pnpm 설치 확인 및 버전 확인
➜ pnpm -v
8.10.0

# 최신 버전 pnpm 으로 업그레이드 
➜ npm i [email protected] -g

# pnpm 설치 다시 확인 및 버전 다시 확인
➜ pnpm -v
8.10.0

프로젝트 생성

➜ mkdir turborepo-example

➜ cd turborepo-example

➜ pnpm init

➜ corepack use [email protected]

➜ code .

워크스페이스 설정

# turborepo-example/pnpm-workspace.yaml

packages:
  - "apps/*"
  - "packages/*"

my-app 생성

➜ mkdir apps

➜ cd apps

➜ pnpx create-next-app@latest

➜ cd ..

turborepo 설치 및 기본 설정

➜ pnpm -w add turbo -D

my-utils 를 Code Generator 로 생성

➜ mkdir packages

➜ pnpm exec turbo gen workspace --name my-utils

➜ pnpm --filter my-utils add typescript -D

➜ pnpm --filter my-utils exec tsc --init
// turborepo-example/packages/my-utils/src/index.ts

export function plusOne(num: number): number {
  return num + 1;
}
{
  "compilerOptions": {
    "target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
    "module": "commonjs" /* Specify what module code is generated. */,
    "declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
    "outDir": "./dist" /* Specify an output folder for all emitted files. */,
    "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
    "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
    "strict": true /* Enable all strict type-checking options. */,
    "skipLibCheck": true /* Skip type checking all .d.ts files. */
  },
  "include": ["src/**/*"]
}
{
  "name": "my-utils",
  "version": "1.0.0",
  "description": "",
  "main": "dist/index.js",
  "types": "dist/index.d.ts",
  "scripts": {
    "build": "tsc",
    "test": "echo \\"Error: no test specified\\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "typescript": "^5"
  },
}