Turbo 是一个高性能的构建系统,结合 pnpm monorepo 使用非常流行。它通过任务调度与缓存机制,大幅提升多仓库开发体验。
vite+(vite-plus) 则提供了一套统一的工具链(vite、vitest、oxlint、oxfmt、rolldown、tsdown、vite task 等),将所有配置集中到 vite.config 中进行管理,从而解决生态碎片化问题。
从 Turbo 迁移到 vite+ 的核心收益也在于此:不仅可以实现与 Turbo 类似的任务调度与缓存能力,还能无缝融入 Vite 生态。从长期来看,这一方向具备很大的发展潜力。
一、移除 Turbo 相关配置
首先,清理项目中所有 Turbo 相关内容:
- 移除依赖:pnpm remove turbo
- 删除配置文件:turbo.json
- 删除缓存目录:.turbo(包括根目录及各 packages 子目录)
- 清理 .gitignore 中的相关配置: .turbo
二、安装与配置 vite+
1. 安装 vite+
- # Windows(PowerShell)
- irm https://vite.plus/ps1 | iex
- # macOS / Linux
- curl -fsSL https://vite.plus | bash
复制代码⚠️ 由于当前项目是基于 Turbo 做任务调度的,因此无法直接使用 vp migrate 自动迁移,需要手动调整配置。
2. 依赖迁移
情况一:使用 workspace 的 catalog / catalogs 管理依赖
- catalog:
- - vite: ^8.0.0
- + vite: npm:@voidzero-dev/vite-plus-core@latest
- - vitest: ^4.1.0
- + vitest: npm:@voidzero-dev/vite-plus-test@latest
- + vite-plus: ^0.1.12
- # catalogs 同理
- + overrides:
- + vite: npm:@voidzero-dev/vite-plus-core@latest
- + vitest: npm:@voidzero-dev/vite-plus-test@latest
复制代码 情况二:直接在 package.json 中管理依赖
- {
- "devDependencies": {
- - "vite": "^8.0.0",
- - "vitest": "^4.1.0",
- + "vite": "npm:@voidzero-dev/vite-plus-core@latest",
- + "vite-plus": "latest",
- + "vitest": "npm:@voidzero-dev/vite-plus-test@latest"
- },
- "pnpm": {
- + "overrides": {
- + "vite": "npm:@voidzero-dev/vite-plus-core@latest",
- + "vitest": "npm:@voidzero-dev/vite-plus-test@latest"
- + }
- }
- }
复制代码 3. vite.config 配置
- - import { defineConfig } from 'vite'
- + import { defineConfig } from 'vite-plus'
- export default defineConfig({
- run: {
- tasks: {...}, // 任务调度
- cache: {...}, // 缓存
- },
- fmt: {...}, // 使用 oxfmt,替代 prettier
- lint: {...}, // 使用 oxlint,替代 eslint
- test: {...}, // vitest
- pack: {...}, // tsdown(库打包,类似 tsup / rollup)
- staged: {...} // 替代 lint-staged
- })
复制代码 三、任务调度与缓存
由于本文实践是 从 Turbo 迁移到 vite+,这里重点说明任务调度与缓存的实现方式。
项目结构
- apps/
- └─ playground
- packages/
- ├─ module-a
- └─ module-b
复制代码 Turbo 原配置
- {
- "$schema": "https://turborepo.com/schema.json",
- "tasks": {
- "build": {
- "outputs": ["dist/**"]
- },
- "dev": {
- "persistent": true,
- "cache": false,
- "dependsOn": ["^build"],
- "interactive": false
- }
- }
- }
复制代码 vite+ 实现方式
<blockquote>
来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |