Fec monorepo project standard
Skill bovinphang/frontend-craft/localized/zh-CN/skills/fec-monorepo-project-standard
用于创建、审查或重构前端 monorepo,包括 pnpm workspace、Turborepo、Nx、多包依赖边界、任务编排、包命名或包发布;中文触发词包括 monorepo、workspace、多包。From its SKILL.md
npx -y skills add bovinphang/frontend-craft --skill fec-monorepo-project-standardAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 19 stars19 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
4.6 KB, ~1.5k tokens by cl100k_base, as published. Nobody here has run it
Monorepo 项目规范
适用于使用 pnpm workspace、Turborepo 或 Nx 的多包前端仓库。
用途
规范 Monorepo 项目的目录结构、依赖管理、任务编排和包发布流程,确保多包协作的构建效率和版本一致性。
流程
- 先确认仓库是否已使用 pnpm workspace、Turborepo 或 Nx,并沿用现有包命名与任务约定。
- 将应用放在
apps/,共享库、配置和工具放在packages/或既有等价目录。 - 内部依赖使用
workspace:*,通过依赖图驱动构建顺序。 - 为 build、lint、test 配置可缓存、可并行、可增量的根任务,并明确输入、输出和环境变量。
- 在 Turborepo/Nx 中配置 affected/changed 范围命令,CI 优先跑受影响包,同时保留主干全量验证入口。
- 发布包前检查包边界、循环依赖、exports、peer dependencies 和版本策略。
工具选择
| 工具 | 适用 | 特点 |
|---|---|---|
| pnpm workspace | 基础 | 依赖提升、链接、脚本聚合 |
| Turborepo | 推荐 | 缓存、并行、依赖图 |
| Nx | 大型 | 增量构建、云缓存、插件生态 |
目录结构
pnpm + Turborepo
├── package.json # 根 package,workspace 配置
├── pnpm-workspace.yaml # workspace 包列表
├── turbo.json # Turborepo 配置
│
├── apps/
│ ├── web/ # 主应用
│ │ ├── package.json
│ │ └── ...
│ ├── admin/ # 管理后台
│ └── docs/ # 文档站
│
├── packages/
│ ├── ui/ # 共享 UI 组件
│ │ ├── package.json
│ │ └── src/
│ ├── utils/ # 工具函数
│ ├── config-eslint/ # 共享 ESLint 配置
│ └── config-typescript/ # 共享 TS 配置
│
└── tooling/ # 构建/测试工具(可选)
└── scripts/
pnpm-workspace.yaml
packages:
- "apps/*"
- "packages/*"
依赖管理
- 内部包使用
workspace:*协议 - 根
package.json统一部分依赖版本,子包可覆盖 - 禁止循环依赖,通过
pnpm why检查
{
"dependencies": {
"@repo/ui": "workspace:*",
"@repo/utils": "workspace:*"
}
}
Turborepo 任务编排
{
"$schema": "https://turbo.build/schema.json",
"tasks": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**", ".next/**"]
},
"lint": {
"dependsOn": ["^build"]
},
"test": {
"dependsOn": ["^build"]
}
}
}
^build表示先执行依赖包的 buildoutputs用于缓存命中判断inputs应包含源码、配置、锁文件和环境相关文件;不要把.envsecret 值写入缓存 key- 远程缓存要区分可信 CI 与本地开发,避免把含敏感信息的产物上传
Nx 任务编排
{
"targetDefaults": {
"build": {
"dependsOn": ["^build"],
"outputs": ["{projectRoot}/dist"],
"cache": true
}
}
}
包命名
- 内部包:
@org/package-name或@repo/package-name - 发布到 npm:遵循
@scope/name规范
约束
- 子包之间通过
workspace:*引用,不发布到 npm 再安装 - 共享配置(ESLint、TS)放在
packages/config-*,子包 extends - 构建顺序由依赖图决定,不手动指定无关依赖
- 根目录执行
pnpm -r build或turbo run build时,所有包按序构建 - 禁止循环依赖,新增包时通过
pnpm why检查依赖链 - CI cache 只缓存依赖安装目录和任务产物,不缓存未验证的构建状态
- affected 构建不能替代发布前全量验证;主干或 release 分支仍需完整质量门禁
预期输出
- Monorepo 目录结构清晰(
apps/应用、packages/共享包、tooling/工具) pnpm-workspace.yaml和turbo.json/nx.json配置正确- 内部包使用
workspace:*协议,无循环依赖 - 构建、lint、test 任务可通过根命令一键执行,缓存命中率高
- CI 能区分 affected 快速反馈和 release 全量验证,缓存配置不会泄露密钥或隐藏依赖边界问题
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.
Gives 0 of the 12 instructions most architecture codebase skills give in ~1.5k tokens
Counted across 811 of the 1,134 authors here whose files we hold, read 2026-08-07
- Ask the user which candidate to explorein 45 of 811, across 15 files
- Apply the deletion test to suspected shallow modulesin 43 of 811, across 15 files
- Read any relevant architecture decision records firstin 31 of 811, across 8 files
- Use exact glossary terms in every suggestionin 30 of 811, across 10 files
- Accept dependencies instead of creating themin 24 of 811, across 5 files
- Include before and after visualisations for each candidatein 24 of 811, across 5 files
- Read the domain glossary before exploringin 24 of 811, across 6 files
- Return results instead of producing side effectsin 23 of 811, across 4 files
- Explore the codebase for shallow modules and frictionin 23 of 811, across 3 files
- Introduce seams only where things varyin 22 of 811, across 3 files
- Reduce the number of methodsin 21 of 811, across 2 files
- Design deep modules with small interfacesin 21 of 811, across 3 files
Said here and by no other author read
- confirm existing workspace tool before changing configuration
- place applications in apps directory
- place shared code in packages directory
- configure cacheable root tasks for build lint test
- configure affected task commands for CI pipelines
- check package boundaries and dependencies before publishing
Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once. Length counted with cl100k_base; the agent that loads this file may tokenize it differently.