Turborepo
Turborepo
์๋ฐ์คํฌ๋ฆฝํธ ๋ฐ ํ์ ์คํฌ๋ฆฝํธ ์ฝ๋๋ฒ ์ด์ค๋ฅผ ์ํ ๊ณ ์ฑ๋ฅ ๋น๋ ์์คํ
๋น๋ ๊ณผ์ ์์์ ์ฑ๋ฅ ํฅ์์ ์ํด ๋ก์ปฌ ์บ์, ๋ฆฌ๋ชจํธ ์บ์, ๋ณ๋ ฌ ์คํ ๋ฑ์ ๊ธฐ๋ฅ์ ์ฝ๊ฒ ์ฌ์ฉํ ์ ์๋๋ก ์ ๊ณต
ํน์ง
vercel ์์ ์ธ์ํ ๋น๋ ์์คํ ๋๊ตฌ
๋ชจ๋ ธ๋ ํฌ ๊ธฐ๋ฅ๋ ์ง์ํ๋ฉฐ ๋ค๋ฅธ ํจํค์ง ๋งค๋์ ์ํฌ์คํ์ด์ค์ ํจ๊ป ์ฌ์ฉ์ด ๊ฐ๋ฅํ๋ค.
๋ชจ๋ ธ๋ ํฌ ํ๊ฒฝ์์๋ ์ฝ๊ณ ๋น ๋ฅด๊ฒ ๊ฐ๋ฐํ ์ ์๋ ๋น๋ ํ๊ฒฝ์ ์ ๊ณตํ๋ ๊ฒ์ด ๋ชฉํ
๋ฃจํธ ์ํฌ์คํ์ด์ค ๋๋ ๊ฐ ์ํฌ์คํ์ด์ค์
turbo.json
์ด๋ผ๋ ํ์ผ์ ์ด์ฉํด์ ์บ์ฑ๊ณผ ํ ์คํฌ ์ค์ผ์คํธ๋ ์ด์ ์ ์ค์ ํ๋ค.
์ฅ์
์ฌ์ฉ์๊ฐ ๋น๋ํ ๋ด์ฉ์ ๊ธฐ์ตํด์ ์ด๋ฏธ ๊ณ์ฐํ ๋ด์ฉ์ ๊ฑด๋๋ (ํ ์คํฌ ์ค์ ๊ธฐ๋ณธ๊ฐ์ด ์บ์ฑ ํ์ฉ)
ํ์์คํฌํ๊ฐ ์๋ ํ์ผ์ ๋ด์ฉ์ ๋ณด๊ณ ๋น๋ํด์ผ ํ ๋ด์ฉ์ ํ์ ํ๋ค.
์ฌ๊ณ ์๋ CPU๋ฅผ ๋ญ๋นํ์ง ์๊ณ , ๋ชจ๋ ์ฝ์ด๋ฅผ ์ต๋๋ก ์ฌ์ฉํด์ ๋ณ๋ ฌ๋ก ์คํ
์๊ฒฉ ๋น๋ ์บ์๋ฅผ ํ์ ๋ฐ CI/CD์ ๊ณต์ ํ์ฌ ๋น๋ ์๋๋ฅผ ๋ํ ์ ์๋ค.
์์ ๊ฐ์ ๊ด๊ณ๋ฅผ ์ ์ํ์ฌ turborepo๊ฐ ๋น๋ ํญ๋ชฉ๊ณผ ์๊ธฐ๋ฅผ ์ต์ ํํ ์ ์๋ค.
์ฃผ์ ๊ธฐ๋ฅ
Running Tasks
ํ ์คํฌ ์ํ
turbo run test // ๊ฐ ์ํฌ์คํ์ด์ค์ 'run test' ์คํฌ๋ฆฝํธ ์คํ
turbo run test --filter=ํน์ ์ํฌ์คํ์ด์ค // ํด๋น ์ํฌ์คํ์ด์ค์ ์คํฌ๋ฆฝํธ ์คํ
Task Dependencies
์์กด ๊ด๊ณ์ ๋ฐ๋ผ ํ ์คํฌ ์คํ + ๋ณ๋ ฌ ์คํ
turbo run lint test build // lint, test, build ๊ฐ ํ
์คํฌ๊ฐ ๋ชจ๋ ๋ณ๋ ฌ๋ก ์คํ๋จ
์์กด ๊ด๊ณ์ ๋ฐ๋ผ ๋จผ์ ์ํ๋์ด์ผ ํ ๊ฒ๋ค์ ํ๋จํ์ฌ ์์ ์ด ์งํ๋จ
์์กด๊ด๊ณ๋ง ์ ์ ์ธํด์ค๋ค๋ฉด ํฐ๋ณด๋ ํฌ๊ฐ ์์์ ์ ๊ณ์ฐํ์ฌ ์ฒ๋ฆฌํด์ฃผ๊ธฐ ๋๋ฌธ์ ์๋ ์ธก๋ฉด์์ ์ผ๋ฐ ํจํค์ง ๋งค๋์ ๋ณด๋ค ๋น ๋ฅด๊ฒ ์ํํ ์ ์๋ค.
Code Generation
์ฝ๋(์ํฌ์คํ์ด์ค) ์์ฑ
turbo gen workspace // ๋น ์ํฌ์คํ์ด์ค ์์ฑ
turbo gen workspace --name @jtwjs/ui
Remote Caching
ํ์ชฝ์์ ๋ฆฌ๋ชจํธ์ ์บ์ฑ์ ํด๋๋ฉด CI/CD ์ชฝ์์ ์บ์ฑ๋ ๋ด์ฉ์ ํ์ฉํด์ ์๋๊ฐ ํฅ์๋จ
turbo login
turbo link // ๋ฒ์
ํด๋ผ์ฐ๋๋ฅผ ์ฌ์ฉํด ์ฝ๊ฒ ๊ตฌํ
pnpm ์ค์ต
turborepo๋ ๋ชจ๋ ํจํค์ง ๋งค๋์ ๋ฅผ ์ฌ์ฉ ๊ฐ๋ฅํ์ง๋ง
pnpm
์ ์ฌ์ฉํ๋ ๊ฒ์ ๊ถ์ฅํ๋ค.
pnpm ํ๊ฒฝ ์ธํ
mkdir turborepo-example
cd turborepo-example
pnpm init
corepack prepare pnpm@8.11.0 --activate
code .
// pnpm-workspace.yaml
packages:
- 'packages/*'
- 'apps/*'
mkdir apps
cd apps
pnpx create-next-app@latest
cd ..
Turbo install
pnpm -w add turbo -D // ํจํค์ง ์ ์ญ์ devDependencies๋ก turbo ์ค์น
workspace ์ถ๊ฐ
mkdir packages
pnpm exec turbo gen workspace --name my-utils
typescript ์ถ๊ฐ
pnpm --filter my-utils add typescript -D
pnpm --filter my-utils exec tsc --init
// tsconfig.json
{
compileOptions: {
//...
"declaration": true, // ํ์
์ ์ ํ์ผ ์์ฑํ๋๋ก ์ค์
"outDir": "./dist" // ์ปดํ์ผ๋ js ํ์ผ์ ์ ์ฅํ๋ ๋๋ ํ ๋ฆฌ ์ค์
},
include: ["src/**/*"]
}
// package.json
{
"name": "jtw-utils",
"version": "0.0.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc"
},
"devDependencies": {
"typescript": "^5"
}
}
pnpm --filter my-utils build
workspace ์์กด์ฑ ์ถ๊ฐ
// apps package.json
"dependencies": {
//...
"my-utils": "workspace:*"
},
pnpm i
turbo ๋ช
๋ น์ด ์ฌ์ฉํ๊ธฐ
pnpm exec turbo build --filter=my-utils // pnpm๊ณผ ๋ฌ๋ฆฌ turbo๋ '='๋ฅผ ๋ถํ๋๊ฒ์ ์ฃผ์

turbo.json
์ ๋ง๋ค๊ณ task๋ฅผ ์ ์ ํด์ฃผ์ด์ผ ํฐ๋ณด ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ ์ ์๋ค.
// turbo.json
{
"$schema": "https://turbo.build/schema.json",
"pipeline": { // pipline์ ์ผ์ข
์ task line
"build": {}
}
}


์คํจํ๋ ๋ช ๋ น์ด๋ฅผ ๋ค์ ์ ๋ ฅํด๋ณด๋ฉด ์ ์์ ์ผ๋ก ์คํ๋๋๊ฒ์ ํ์ธํ ์ ์๋ค.
๋ ๋ฒ์งธ ์คํ๋ถํฐ๋
cache
๋์ด ์ํ์๊ฐ์ด 980ms -> 50ms๋ก ๋จ์ถ๋๊ฒ์ ํ์ธํ ์ ์๋ค.
๋ชจ๋ ์ํฌ์คํ์ด์ค ๋ช
๋ น์ด ์คํ
--filter
๋ฅผ ์์ฑํ์ง ์์ผ๋ฉด ๋ชจ๋ ์ํฌ์คํ์ด์ค๋ฅผ ๋๋ฉด์ ์คํฌ๋ฆฝํธ ์คํ
pnpm exec turbo build
build outputs ์ค์
{
"$schema": "https://turbo.build/schema.json",
"pipeline": {
"build": {
"outputs": ["./next/**", "!.next/cahce/**", "dist/**"]
}
}
}
build ๊ด๊ณ ์ค์ ํ๊ธฐ
dependsOn
์ค์ ์ ํตํด ๋น๋ํ ๋ ์์กดํ๊ณ ์๋ ๊ฒ๋ค์ ๊ด๊ณ๋ฅผ ์ค์ ํ ์ ์๋ค.app์ ์ฝ๋๋ง ๋ณ๊ฒฝ๋๋ค๋ฉด ์์กดํ๋ ๊ฒ๋ค์ ์บ์ฑ๋ ๊ฒ์ ์ฌ์ฉํ๊ณ ์์กดํ๋ ๊ฒ๋ค์ ๋ณ๊ฒฝ์ฌํญ์ด ์๊ธด๋ค๋ฉด ์บ์ฑ์์ด ๋ค์ ๋น๋๊ฐ ์ผ์ด๋๋ค.
{
"$schema": "https://turbo.build/schema.json",
"pipeline": {
"build": {
"dependsOn": ["^build"], // ์์ "^" ๊บฝ์ ๋ฅผ ๋ถํ๋ฉด ์์กดํ๊ณ ์๋ ๋ชจ๋ ๊ฒ์ ๋น๋ํ๋ค๋ ์๊ธฐ
"outputs": ["./next/**", "!.next/cahce/**", "dist/**"]
}
}
}
์ํฌ์คํ์ด์ค ๊ฐ ๋น๋ ์ต์
์ ๋ค๋ฅด๊ฒ ์ค์ ํ๊ธฐ
๋ฃจํธ์ ์กด์ฌํ๋
turbo.json
์ผ๋ก ํ๊ณณ์์ ๊ด๋ฆฌํ๋ค๋ฉด#
์ ํตํด ์ํฌ์คํ์ด์ค๊ฐ ๋น๋ ์ต์ ์ ๋ค๋ฅด๊ฒ ์ค์ ํ ์ ์์ง๋ง ์ํฌ์คํ์ด์ค๊ฐ ๋ง์์ง๋ฉด ๋ณต์กํด์ง๋ค.๋ ๋ฒ์งธ ๋ฐฉ๋ฒ์ผ๋ก, ๊ฐ ์ํฌ์คํ์ด์ค ๊ฐ์
turbo.json
์ ์์ฑํ์ฌ ์ต์ ์ ๋ค๋ฅด๊ฒ ๊ด๋ฆฌํ ์ ์์ต๋๋ค. Turborepo์์ ์ถ๊ฐ๋๋ ๊ธฐ๋ฅ๋ค์ ์ดํด๋ณด๋ฉด ์ํฌ์คํ์ด์ค ์์ ๊ธฐ๋ฅ(์:turbo.json
์์ ๋ฑ)์ ์ฒ๋ฆฌ ์์๊ฐ ์ ์ ๋ ์ถ๊ฐ๋๋ ์ถ์ธ๋ผ ํด๋น ๋ฐฉ์์ ์ฌ์ฉํ๋ ๊ฒ์ ์ถ์ฒ
// root์ ์กด์ฌํ๋ turbo.json
{
"$schema": "https://turbo.build/schema.json",
"pipeline": {
"my-app#build": {
"dependsOn": ["^build"],
"outputs": ["./next/**", "!.next/cahce/**"]
},
"my-utils#build": {
"dependsOn": ["^build"],
"outputs": ["dist/**"]
}
}
}
์ํฌ์คํ์ด์ค ๊ฐ๋ฐ ์๋ฒ ๋์ฐ๊ธฐ
pnpm exec turbo dev --filter=my-app

๋ง์ฐฌ๊ฐ์ง๋ก
turbo.json
์ dev ๊ด๋ จํ ์ ์๊ฐ ๋์ด์์ง ์์ ํด๋น ๋ช ๋ น์ด๊ฐ ์คํจํ์ฌturbo.json
์ ์ถ๊ฐ๋ก ์ ์ํด์ฃผ์ด์ผ ํ๋ค.๊ฐ๋ฐ ์๋ฒ ์คํ์ ์บ์ฑ์ด๋๋ฉด ์๋๋ฏ๋ก
cache
์ต์ ์ false๋ก ์ค์ ๊ณ์ ์คํํด์ผํ๋ ๊ฒ๋ค์ turborepo์์
cache: false
,persistent: true
์ค์ ์ ์ถ๊ฐํ ๊ฒ์ ๊ถ์ฅํ๋ค.
{
"$schema": "https://turbo.build/schema.json",
"pipeline": {
"my-app#build": {
"dependsOn": ["^build"],
"outputs": ["./next/**", "!.next/cahce/**"]
},
"jtw-utils#build": {
"dependsOn": ["^build"],
"outputs": ["dist/**"]
},
"my-app#dev": {
"cache": false,
"persistent": true
}
}
}
Ref
Remote Cache
Graph
graphviz ์ค์น
Last updated