watch

根据代码更改,重新运行代码库中的任务。

¥Re-run tasks in your repository, based on code changes.

Terminal
turbo watch [tasks]

turbo watch 具有依赖感知功能,这意味着任务将按照 turbo.json 中的配置 的顺序重新运行。

¥turbo watch is dependency-aware, meaning tasks will re-run in the order configured in turbo.json.

如果没有提供任何任务,turbo 将显示存储库中包可用的任务。

¥If no tasks are provided, turbo will display what tasks are available for the packages in the repository.

Terminal
turbo watch

turbo watch 与持久任务结合使用

¥Using turbo watch with persistent tasks

持久任务标记为 "persistent": true,表示它们不会退出。因此,它们在你的任务图中不可依赖。

¥Persistent tasks are marked with "persistent": true, meaning they won't exit. Because of this, they cannot be depended on in your task graph.

这意味着使用 turbo watch 时,持久性任务将被忽略,其工作方式与使用 turbo run 时相同,从而允许同时运行持久性任务和非持久性任务。

¥This means that persistent tasks will be ignored when using turbo watch, working the same way they do with turbo run, allowing persistent and non-persistent tasks to be run at the same time.

依赖感知的持久任务

¥Dependency-aware persistent tasks

当你的脚本具有内置的监视程序(例如 next dev)能够检测依赖的变化时,你无需使用 turbo watch。相反,使用脚本的内置监视器,并使用 "persistent": true 将任务标记为长时间运行。

¥When your script has a built-in watcher (like next dev) capable of detecting changes in dependencies, you don't need to use turbo watch. Instead, use your script's built-in watcher and mark the task as long-running using "persistent": true.

没有依赖感知的持久任务

¥Persistent tasks without dependency awareness

某些工具与 monorepo 不兼容,并且不会在依赖中热重载模块。在这种情况下,你应该将任务标记为 interruptible: true,以便在检测到相关更改时让 turbo watch 重新启动该任务。

¥Some tools aren't monorepo-friendly, and do not hot-reload modules in dependencies. In those cases, you should mark the task as interruptible: true to have turbo watch restart the task when relevant changes are detected.

限制

¥Limitations

缓存

¥Caching

使用监视模式缓存任务目前处于实验阶段,使用 --experimental-write-cache 标志。

¥Caching tasks with Watch Mode is currently experimental, under the --experimental-write-cache flag.

Terminal
turbo watch your-tasks --experimental-write-cache

任务输出

¥Task outputs

如果你的任务需要写入已签入源代码管理的文件,则监视模式可能会陷入无限循环。这是因为监视模式会监视文件更改,并会在发生更改的包中重新运行任务。如果任务创建了更改,则更改将再次触发该任务。

¥If you have tasks that write to files checked into source control, there is a possibility that Watch Mode will run in an infinite loop. This is because Watch Mode watches your files for changes and will re-run tasks in packages that have changed. If a task creates a change, then that will trigger the task again.

监视模式有一些逻辑可以使用文件哈希来防止这种情况发生,但这并非万无一失。为避免此问题,我们建议从 git 中删除所有任务输出。

¥Watch Mode has some logic to prevent this from happening using file hashes, but it isn't foolproof. To avoid this issue, we recommend removing any task outputs from git.