prune

为目标软件包生成部分 monorepo。输出将被放置到名为 out 的目录中,其中包含以下内容:

¥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.

  • package.json 的副本。

    ¥A copy of the root package.json.

Terminal
turbo prune [package]

示例

¥Example

从具有以下结构的仓库开始:

¥Starting with a repository with the following structure:

package.json
pnpm-lock.yaml

运行 turbo prune frontend 以在 out 目录中为 frontend 应用生成精简的工作区:

¥Run turbo prune frontend to generate a pruned workspace for the frontend application in an out directory:

package.json
pnpm-lock.yaml (partial)

选项

¥Options

--docker

默认为 false

¥Defaults to false.

更改输出目录,使其更易于与 Docker 最佳实践和层缓存 一起使用。目录将包含:

¥Alter the output directory to make it easier to use with Docker best practices and layer caching. The directory will contain:

  • 一个名为 json 的文件夹,其中包含已精简工作区的 package.json 文件。

    ¥A folder named json with the pruned workspace's package.json files.

  • 一个名为 full 的文件夹,其中包含已精简工作区中构建目标所需的内部包的完整源代码。

    ¥A folder named full with 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.

使用与上述相同的示例,运行 turbo prune frontend --docker 将生成以下内容:

¥Using the same example from above, running turbo prune frontend --docker will generate the following:

pnpm-lock.yaml (partial)
package.json (from repo root)
package.json (from repo root)
package.json
package.json
package.json

--out-dir <path>

默认为 ./out

¥Defaults to ./out.

自定义生成修剪输出的目录。

¥Customize the directory the pruned output is generated in.

--use-gitignore[=<bool>]

默认:true

¥Default: true

将文件复制到输出目录时,请考虑 .gitignore 文件。

¥Respect .gitignore file(s) when copying files to the output directory.

pnpm deploy 的比较

¥Comparison to pnpm deploy

虽然 turbo prunepnpm deploy 都用于隔离 monorepo 中的包,但它们服务于不同的用途并产生不同的输出。

¥While both turbo prune and pnpm deploy are used to isolate packages in a monorepo, they serve different purposes and produce different outputs.

turbo prune 生成部分 monorepo,pnpm deploy 生成仅包含目标包内容的目录。

¥Where turbo prune generates a partial monorepo, pnpm deploy generates a directory that only contains the contents of the target package.

pnpm deploy 生成的目录包含一个独立的 node_modules 文件,其中包含硬链接的内部依赖。这会生成一个可移植的包,可以直接复制到服务器并使用,无需额外步骤。由于重点是生成独立的可部署包,因此不会保留仓库结构。

¥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.