Open developerasun opened 2 years ago
Add turbo as a development dependency in the root of your monorepo.
pnpm add turbo -Dw
The turbo package is a little shell that will install the proper turbo-
- package for you operating system and architecture.
In the root of your monorepo, create an empty file named turbo.json. This will hold the configuration for Turborepo. If your git repo's base branch is not origin/master, then you need to specify a baseBranch too. For example, origin/main.
{
"$schema": "https://turborepo.org/schema.json",
"baseBranch": "origin/main"
}
# deprecated
pnpx create-turbo@latest
# command
pnpm dlx create-turbo@latest
To manage dependencies within workspaces in your monorepo, you will need to run commands that will only manage the dependencies of each workspace rather than for the entire monorepo.
pnpm add <package> --filter <workspace>
For example,
# install
pnpm add react --filter web // pnpm add react --filter web
# uninstall
pnpm uninstall <package> --filter <workspace> // pnpm uninstall react --filter web
# update
pnpm up <package> --filter <workspace> // pnpm up react --filter web
# inject dev dependency to project (in project root)
pnpm install -D (package-name-in-package.json) (project-name-in-package.json)
Filtering packages allows you to target your tasks to only the packages you care about. Turborepo supports a pnpm-like --filter flag that allows you to select the packages that will act as "entry points" into your monorepo's package/task graph. You can filter your project by package name, package directory, whether packages include dependents/dependencies, and by changes in git history.
turbo will run each task against each matched package, ensuring that any dependencies are run first, according to the pipeline specification in turbo.json.
To define your monorepo's task dependency graph, use the pipeline key in the turbo.json configuration file at the root of monorepo. turbo interprets this configuration to optimally schedule, execute, and cache the outputs of each of the package.json scripts defined in your workspaces.
Each key in the pipeline object is the name of a package.json script that can be executed by turbo run. You can specify its dependencies with the dependsOn key beneath it as well as some other options related to caching. For more information on configuring your pipeline, see the Pipelines documentation.
Packages that do not have the specified script defined in their package.json's list of scripts will be ignored by turbo.
{
"$schema": "https://turborepo.org/schema.json",
"pipeline": {
"build": {
// A package's `build` script depends on that package's
// dependencies' and devDependencies'
// `build` tasks being completed first
// (the `^` symbol signifies `upstream`).
"dependsOn": ["^build"],
// note: output globs are relative to each package's `package.json`
// (and not the monorepo root)
"outputs": [".next/**"]
},
"test": {
// A package's `test` script depends on that package's
// own `build` script being completed first.
"dependsOn": ["build"],
"outputs": [],
// A package's `test` script should only be rerun when
// either a `.tsx` or `.ts` file has changed in `src` or `test` folders.
"inputs": ["src/**/*.tsx", "src/**/*.ts", "test/**/*.ts", "test/**/*.tsx"]
},
"lint": {
// A package's `lint` script has no dependencies and
// can be run whenever. It also has no filesystem outputs.
"outputs": []
},
"deploy": {
// A package's `deploy` script depends on the `build`,
// `test`, and `lint` scripts of the same package
// being completed. It also has no filesystem outputs.
"dependsOn": ["build", "test", "lint"],
"outputs": []
}
}
}
topic : understanding turborepo build system in software development
read this
Add Turborepo to your existing monorepo
Configure workspaces
reference