prune
API reference for the `turbo prune` command
Generate a partial monorepo for a target package. The output will be placed into a directory named out containing the following:
- The full source code of all internal packages needed to build the target.
- A pruned lockfile containing the subset of the original lockfile needed to build the target.
- A copy of the root
package.json.
turbo prune [package]Example
Starting with a repository with the following structure:
Run turbo prune frontend to generate a pruned workspace for the frontend application in an out directory:
Options
--docker
Defaults to false.
Alter the output directory to make it easier to use with Docker best practices and layer caching. For an example Dockerfile using this flag, see the Docker guide. The directory will contain:
- A folder named
jsonwith the pruned workspace'spackage.jsonfiles. - A folder named
fullwith the pruned workspace's full source code for the internal packages needed to build the target. - A pruned lockfile containing the subset of the original lockfile needed to build the target.
Using the same example from above, running turbo prune frontend --docker will generate the following:
--out-dir <path>
Defaults to ./out.
Customize the directory the pruned output is generated in.
--use-gitignore[=<bool>]
Default: true
Respect .gitignore file(s) when copying files to the output directory.
Including globalDependencies
By default, turbo prune does not copy files referenced by globalDependencies into the output directory. The globalDependencies field is preserved in the pruned turbo.json, but the files themselves (e.g., a root tsconfig.json or .env) are not included.
Enable the pruneIncludesGlobalFiles future flag to copy these files:
{
"globalDependencies": ["tsconfig.json", ".env"],
"futureFlags": {
"pruneIncludesGlobalFiles": true,
},
}With this flag, all files matching the globalDependencies globs will be included in the pruned output. In --docker mode, they are copied to both the full and json directories.
Comparison to pnpm deploy
While both turbo prune and pnpm deploy are used to isolate packages in a monorepo, they serve different purposes and produce different outputs.
Where turbo prune generates a partial monorepo, pnpm deploy generates a directory that only contains the contents of the target package.
The pnpm deploy generated directory has a self-contained node_modules with hard linked internal dependencies.
This results in a portable package that can be directly copied to a server and used without additional steps.
The repository structure is not retained, as the focus is on producing a standalone deployable package.