安装

使用以下命令开始使用 Turborepo:

¥Get started with Turborepo in a few moments using:

Terminal
pnpm dlx create-turbo@latest

启动存储库将包含:

¥The starter repository will have:

  • 两个可部署的应用

    ¥Two deployable applications

  • 三个共享库可用于 monorepo 的其余部分

    ¥Three shared libraries for use in the rest of the monorepo

有关入门版 访问 GitHub 上基本入门指南的 README 文件 的更多详细信息。你还可以使用更符合你工具需求的 使用示例

¥For more details on the starter, visit the README for the basic starter on GitHub. You can also use an example that more closely fits your tooling interests.

安装 turbo

¥Installing turbo

turbo 既可以全局安装,也可以安装在你的代码库中。我们强烈建议你同时安装这两种方式,以便你可以利用快速、便捷的工作流程,并为在你的代码库中工作的所有开发者提供稳定的 turbo 版本。

¥turbo can be installed both globally and in your repository. We highly recommend installing both ways so you can take advantage of fast, convenient workflows and a stable version of turbo for all developers working in your repository.

全局安装

¥Global installation

全局安装 turbo 为你的本地工作流程带来了灵活性和速度。

¥A global install of turbo brings flexibility and speed to your local workflows.

Terminal
pnpm add turbo --global

全局安装后,你可以从终端通过 turbo 运行脚本,快速运行可在存储库中使用的一次性命令。例如:

¥Once installed globally, you can run your scripts through turbo from your terminal, quickly running one-off commands to use within your repository. For example:

  • turbo build:按照你的仓库的依赖图运行 build 脚本

    ¥turbo build: Run build scripts following your repository's dependency graph

  • turbo build --filter=docs --dry:快速打印 docs 包的 build 任务概要(无需运行)

    ¥turbo build --filter=docs --dry: Quickly print an outline of the build task for your docs package (without running it)

  • turbo generate:运行 生成器 以将新代码添加到你的仓库

    ¥turbo generate: Run Generators to add new code to your repository

  • cd apps/docs && turbo build:运行 docs 包及其依赖中的 build 脚本。更多信息请访问 自动包作用域部分

    ¥cd apps/docs && turbo build: Run the build script in the docs package and its dependencies. For more, visit the Automatic Package Scoping section.

Good to know: 

turboturbo run 的别名。例如,turbo buildturbo run build 都将运行你的 build 任务。

¥turbo is an alias for turbo run. For example, turbo build and turbo run build will both run your build task.

Avoid multiple global installations

如果你之前已经安装了全局 turbo,请确保使用与现有安装相同的包管理器,以避免出现意外行为。你可以快速检查之前使用 turbo bin 的包管理器。

¥If you've installed global turbo before, make sure you use the same package manager as your existing installation to avoid unexpected behaviors. You can quickly check which package manager you previously used with turbo bin.

在 CI 中使用全局 turbo

¥Using global turbo in CI

你还可以在创建 CI 流水线时利用全局 turbo。访问 构建 CI 指南了解更多信息。

¥You can also take advantage of global turbo when creating your CI pipelines. Visit the Constructing CI guide for more information.

仓库安装

¥Repository installation

在代码库中与其他开发者协作时,最好固定依赖的版本。你可以将 turbo 添加为存储库根目录中的 devDependency 来执行此操作:

¥When collaborating with other developers in a repository, it's a good idea to pin versions of dependencies. You can do this with turbo by adding it as a devDependency in the root of your repository:

Terminal
pnpm add turbo --save-dev --ignore-workspace-root-check

你可以继续使用全局安装的 turbo 来运行命令。全局 turbo 将遵循代码库的本地版本(如果存在)。

¥You can continue to use your global installation of turbo to run commands. Global turbo will defer to the local version of your repository if it exists.

这让你能够充分利用这两种安装方式:轻松在终端中运行命令,同时维护固定版本,以便存储库中的所有开发者保持一致的使用。

¥This lets you to get the best of both installations: easily run commands in your terminal while maintaining a pinned version for consistent usage for all developers in the repository.