Turborepo
A JavaScript/TypeScript monorepo build tool
A JavaScript/TypeScript monorepo build tool
Turborepo is a JavaScript/TypeScript monorepo build system developed by Jared Palmer in 2021 and later acquired by Vercel. Its core goal is to dramatically improve build speed in large codebases.
Its key features are smart caching and parallel execution. Packages with no code changes retrieve previous build results from the cache, and tasks with no dependencies run concurrently. It supports both a local cache and a remote cache (Vercel Remote Cache, or your own server).
Pipelines are defined in turbo.json. When you declare each task's dependencies (dependsOn), outputs (outputs), and cache settings (cache), Turborepo automatically calculates the optimal execution order and parallelization. For example, you configure build to depend on ^build (building dependent packages) and test to depend on build.
In practice, it is used when managing a frontend (Next.js, React), a backend (Node.js API), and shared libraries in a single repository. Using a remote cache in CI lets team members share build results, and the total build time is often reduced by more than 80%.
// turbo.json - ํ์ดํ๋ผ์ธ ์ค์
{
"$schema": "https://turbo.build/schema.json",
"globalDependencies": [".env"],
"pipeline": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**", ".next/**", "build/**"],
"env": ["NODE_ENV"]
},
"test": {
"dependsOn": ["build"],
"outputs": ["coverage/**"],
"inputs": ["src/**", "test/**"]
},
"lint": {
"outputs": []
},
"dev": {
"cache": false,
"persistent": true
},
"type-check": {
"dependsOn": ["^build"],
"outputs": []
}
}
}
// package.json (๋ฃจํธ)
{
"name": "my-monorepo",
"private": true,
"workspaces": [
"apps/*",
"packages/*"
],
"scripts": {
"build": "turbo run build",
"test": "turbo run test",
"lint": "turbo run lint",
"dev": "turbo run dev",
"build:filter": "turbo run build --filter=@my/web...",
"test:changed": "turbo run test --filter=[origin/main]"
},
"devDependencies": {
"turbo": "^1.10.0"
}
}
// ํ๋ก์ ํธ ๊ตฌ์กฐ
// apps/
// web/ # Next.js ์ฑ
// api/ # Node.js API
// packages/
// ui/ # ๊ณต์ UI ์ปดํฌ๋ํธ
// utils/ # ์ ํธ๋ฆฌํฐ ํจ์
// config/ # ๊ณต์ ์ค์ (ESLint, TypeScript)
// packages/ui/package.json
{
"name": "@my/ui",
"version": "0.0.0",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsup src/index.ts --format cjs,esm --dts",
"lint": "eslint src/",
"test": "vitest run"
}
}
// apps/web/package.json
{
"name": "@my/web",
"dependencies": {
"@my/ui": "workspace:*",
"@my/utils": "workspace:*"
}
}
// ๋ช
๋ น์ด ์์
// turbo run build # ์ ์ฒด ๋น๋
// turbo run build --filter=@my/web # web ์ฑ๋ง ๋น๋
// turbo run build --filter=...@my/ui # ui์ ์์กดํ๋ ๋ชจ๋ ํจํค์ง ๋น๋
// turbo run test --concurrency=4 # ๋์ ์คํ ์ ์ ํ
// TURBO_TEAM=my-team TURBO_TOKEN=xxx turbo run build # ์๊ฒฉ ์บ์
Senior: "The CI build takes 15 minutes, so merging PRs is far too slow. If we add the Turborepo remote cache, only the changed packages will be built, so it should get faster."
Junior: "Is Vercel Remote Cache free? Or do we have to set it up ourselves?"
Senior: "You can use it for free by connecting to Vercel. Or you can also set up your own server with ducktors/turborepo-remote-cache."
Interviewer: "If you have monorepo experience, which tools did you use?"
Candidate: "I used pnpm workspace together with Turborepo. Turborepo's smart caching cut CI time from 15 minutes to 3 minutes, and I improved efficiency by building/testing only the changed packages with the --filter option. Sharing build results among team members through the remote cache also sped up local development."
Take a mock interview on this topic โ WIA SOOM AI Interview ยท Start for free
Reviewer: "If you don't specify outputs in turbo.json, caching won't work properly. Please add the build output paths."
Developer: "Should I add the dist folder and the .next folder? I think environment variables should also be included in the cache key."
Reviewer: "Right, if you put NODE_ENV in the env array, the cache is separated by environment."