Getting started with Turborepo
2 min read
1 year ago
Published on May 23, 2024
This response is partially generated with the help of AI. It may contain inaccuracies.
Table of Contents
Step-by-Step Tutorial: Getting Started with Turborepo
-
Understanding Mono Repositories and Turbo Repo:
- Mono Repo: A collection of multiple apps and packages in a single code base.
- Turbo Repo: A tool from Versl that manages mono repositories efficiently and speeds up tasks.
-
Setting Up a Mono Repository with Turbo Repo:
- Run
npx create turbo latestto create a new Turbo Repo. - Choose the directory for the new Turbo Repo.
- Once created, you can run commands like
npm run buildandnpm run dev.
- Run
-
Workspace and Packages in Turbo Repo:
- Workspaces: Each application or package in the mono repo is its own workspace.
- Packages: Shared libraries or configurations shared between apps in the mono repo.
-
Managing Dependencies and Workspaces:
- Declare dependencies in the
package.jsonof each workspace. - Use
turbo.jsonto define pipelines for running tasks across the mono repo.
- Declare dependencies in the
-
Running Tasks in Turbo Repo:
- Use
turbo run <task>to run tasks across workspaces. - Use
turbo run <task> --workspace <workspace_name>to run tasks on specific workspaces.
- Use
-
Adding Tailwind CSS to Mono Repo:
- Add Tailwind CSS to a specific workspace using the
--workspaceflag. - Share Tailwind CSS config by creating a shared package and referencing it in workspaces.
- Add Tailwind CSS to a specific workspace using the
-
Configuring Tailwind CSS in Next.js Apps:
- Create a
globals.cssfile with Tailwind directives. - Import the global styles in the
_app.jsfile of the Next.js app.
- Create a
-
Testing Tailwind CSS in Mono Repo:
- Ensure dependencies are synced between root and individual workspaces.
- Run
npm run devto start the development server and test Tailwind CSS changes.
-
Optimizing Build Process in Turbo Repo:
- Understand caching behavior in Turbo Repo to speed up build processes.
- Use
turbo run buildto build apps and packages efficiently.
-
Finalizing Tailwind CSS Implementation:
- Adjust Tailwind config to include specific directories like pages and components.
- Verify that Tailwind CSS is working across different apps and shared packages in the mono repo.
By following these steps, you can efficiently set up a mono repository using Turbo Repo and integrate Tailwind CSS to share configurations and styles across multiple applications.