• Discover
  • Collections
  • Board
  • Create
  • Profile
  • Settings
Paths

Setting Up a New Turborepo Project

Setting Up a New Turborepo Project

2 min read

Overview

This lesson provides a hands-on guide to initializing a new monorepo with Turborepo or integrating Turborepo into an existing workspace. We'll walk through the create-turbo command, understand the initial project structure, and learn how to define and execute tasks within this new high-performance environment. Getting started correctly ensures you can immediately benefit from Turborepo's speed and efficiency.

Key Points

  • Initializing a New Monorepo:

  • Use npx create-turbo@latest to scaffold a new monorepo with a default structure and turbo.json configuration.

  • It sets up a basic apps and packages directory, along with a root package.json that configures npm (or Yarn/pnpm) workspaces.

  • Integrating into an Existing Monorepo:

  • Install turbo as a dev dependency: npm install turbo --save-dev (or yarn add turbo -D, pnpm add turbo -D).

  • Create a turbo.json file at the root of your monorepo.

  • Define your pipeline tasks in turbo.json, mapping common scripts (e.g., build, test, lint) to Turborepo's caching and dependency management.

  • Basic Task Definition:

  • In turbo.json, the pipeline object defines how different script names (like "build" or "test") should behave.

  • dependsOn: Specifies task dependencies (e.g., build often dependsOn ^build to build dependencies first).

  • outputs: Defines which files/directories are considered outputs of a task for caching.

  • cache: Boolean to enable/disable caching for a task.

Quick Example

bash
npx create-turbo@latest my-turborepo --npm

This command creates a directory my-turborepo with a basic structure:

my-turborepo/
├── apps/
│   ├── web/        # Example Next.js app
│   └── docs/       # Example Next.js docs app
├── packages/
│   ├── ui/         # Example React component library
│   └── config/     # Example shared configuration
└── turbo.json      # Turborepo configuration
└── package.json    # Root package.json with workspaces

To run tasks: turbo run build will build all projects according to turbo.json.

Summary

Setting up Turborepo, whether from scratch or integrating into an existing project, is straightforward. The create-turbo command simplifies initialization, and the turbo.json file provides a powerful way to define and manage your build pipeline, instantly leveraging Turborepo's performance benefits for your monorepo.

End of lesson
👏Well done!
Previous Lesson
Quiz: Introducing Turborepo
Next Lesson
Advanced Turborepo Features and Optimizations

Course Content

0% Complete0/9 Lessons

What is a Monorepo?

Monorepo Best Practices & Tooling Overview

Quiz

Setting Up a New Turborepo Project

Advanced Turborepo Features and Optimizations

Quiz

Course Content

0% Complete0/9 Lessons

What is a Monorepo?

Monorepo Best Practices & Tooling Overview

Quiz

Setting Up a New Turborepo Project

Advanced Turborepo Features and Optimizations

Quiz