多语言支持
Turborepo 基于 JavaScript 生态系统的约定构建,用于查找要执行的脚本和任务。 - 但它不关心这些脚本的作用。按照 在 JavaScript 工作区中指定包的指南 的原则,你可以将任何其他语言或工具链添加到 Turborepo。
¥Turborepo is built on the conventions of the JavaScript ecosystem to find scripts and tasks to execute - but it doesn't care what those scripts do. Following the guidance for specifying a package in a JavaScript workspace, you can add any other language or toolchain to Turborepo.
例如,你的代码库中的 ./cli
目录下可能有一个 Rust 项目。要将此目录作为包添加到 JavaScript 包管理器的工作区,请将该目录添加到工作区定义中:
¥As an example, you may have a Rust project in the ./cli
directory in your repository. To add this directory as a package to your JavaScript package manager's workspace, add the directory to the workspace definition:
然后,将 package.json
添加到目录:
¥Then, add a package.json
to the directory:
现在,当你使用 turbo build
时,./cli/package.json
中的 "build"
脚本将被包含在 turbo
运行的任务中。
¥Now, when you use turbo build
, the "build"
script in ./cli/package.json
will be included into the tasks that turbo
runs.
缓存构建工件
¥Caching build artifacts
确保你的构建输出已在 turbo.json
中使用 输出键 缓存。如果 Rust CLI 使用 Cargo 编译,则会在 target/release
目录中创建一个发布版本,我们可以使用以下命令缓存它:
¥Ensure that the outputs for your builds are being cached with the outputs key in turbo.json
. In the case of a Rust CLI being compiled with cargo, a release build would be created in the target/release
directory and we can cache it using:


创建依赖
¥Creating dependency relationships
由于该目录现在是包管理器工作区的一部分,因此你可以像创建 JavaScript 包一样创建依赖。
¥Because the directory is now a part of the package manager's workspace, you can create dependencies exactly the same as you do for your JavaScript packages.
例如,如果你想确保上面的 rust-cli
"package" 在 web
应用之前构建,请将其安装到 web
应用的依赖中:
¥For instance, if you wanted to make sure that the rust-cli
"package" from above is built before your web
application, install it into the dependencies for the web
application:
假设 turbo.json
任务包含如下 build
任务:
¥Given a turbo.json
with a build
task like:


turbo build
将首先为 Rust CLI 创建工件,然后构建 web
应用。
¥turbo build
will first create the artifacts for the Rust CLI and then build the web
application.