Overview
This lesson provides a hands-on guide to initializing a new Turborepo monorepo. We'll start from scratch and explore the basic structure created by the Turborepo CLI, setting the foundation for our migration.
Key Points
-
Using
create-turbo: The easiest way to start is with the official initializer, which sets up a basic monorepo structure with exampleappsandpackages. -
Initial Project Structure: A newly created Turborepo typically includes:
-
A root
package.jsondefiningworkspaces. -
A
turbo.jsonfor pipeline configuration. -
An
appsdirectory (e.g.,web,docs). -
A
packagesdirectory (e.g.,ui,eslint-config,tsconfig). -
Defining Workspaces in
package.json: Theworkspacesarray in the rootpackage.jsontells your package manager (npm, Yarn, pnpm) which directories contain sub-projects. -
Adding New Workspaces: To add a new application or package, simply create its directory within
apps/orpackages/and ensure its name is included in the rootpackage.jsonworkspacesarray.
Quick Example
To initialize your Turborepo:
bash npx create-turbo@latest -- --appName=my-next-app --packageManager=pnpm
After initialization, your package.json might look like this:
json{ "name": "my-monorepo", "version": "1. 0. 0", "private": true, "workspaces": ```json [ "apps/*", "packages/*" ]
}
## Summary
Initializing a Turborepo with `create-turbo` provides a solid starting point. Understanding the roles of the root `package.json`'s `workspaces` and `turbo.json` is fundamental for managing your monorepo's projects and tasks effectively.