[翻译中]面向未来的前端构建工具、npm/yarn/pnpm 的继任者:(Turbo) Turborepo

643 阅读1分钟

Turborepo 是一个用于 JavaScript 和 TypeScript 代码库的高性能构建系统。 通过增量构建、智能远程缓存和优化的任务调度,Turborepo 可以将构建速度提高 85% 或更多,使各种规模的团队都能够维护一个快速有效的构建系统,该系统可以随着代码库和团队的成长而扩展。

下面我们来看下如何把 Turborepo 运用到我们的前端项目中吧!

标题:《将Turborepo添加到你现有的项目中》

Turborepo可以在任何项目中使用,以加快package.json中脚本的执行速度。

在你安装了turbo之后,你就可以从turbo而不是软件包管理器中运行你所有的package.json任务。

通过正确配置你的turbo.json,你会注意到缓存如何帮助你的任务运行得更快。

Quickstart

  1. If you don't have one already, create a new application:

  2. Install turbo globally:

  3. Add a turbo.json file at the base of your new repository:

For more information on configuring your turbo.json, see the Configuration Options documentation.

{ "$schema": "https://turbo.build/schema.json", "pipeline": { "build": { "outputs": ["dist/**"] }, "lint": {} }}

Some Vite starters ship with a package.json that looks like this:

package.json

{  "scripts": {    "build": "tsc && vite build"  }}

We recommend splitting these into a lint and build script.

package.json

{  "scripts": {    "build": "vite build",    "lint": "tsc"  }}

This means that Turbo can schedule them separately.

  1. Edit .gitignore

Add .turbo to your .gitignore file. The CLI uses these folders for logs and certain task outputs.

+ .turbo
  1. Try running build and lint with turbo:
turbo build lint

This runs build and lint at the same time.

  1. Without making any changes to the code, try running build and lint again:
turbo build lint

You should see terminal output like this:

 Tasks:    2 successful, 2 totalCached:    2 cached, 2 total  Time:    185ms >>> FULL TURBO

Congratulations - you just completed a build and lint in under 200ms.

To learn how this is possible, check out our core concepts docs.

  1. Try running dev with turbo:
turbo dev

You'll notice that your dev script starts up. You can use turbo to run any script in your package.json.

原文链接:Add Turborepo to your existing project – Turborepo