首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在Monorepo中运行开发中的多个包

如何在Monorepo中运行开发中的多个包
EN

Stack Overflow用户
提问于 2020-07-18 02:12:06
回答 1查看 3.2K关注 0票数 3

我有一个使用lerna和纱线工作区的monorepo,用于前端应用程序和lib。我在根package.json中添加了一系列npm脚本,以管理每个包(app、lib、plugin),就像本文末尾的代码一样。问题是我的根package.json越来越大,我才刚刚开始。其他问题是,如果我需要开发在客户关系管理中使用的组件,在组件库中使用i18n库,我需要在3个独立的终端窗口中启动3个包,并且有可能同时开发更多的依赖程序包。

例如,我认为在客户关系管理中安装的每个包(使用--并行)中的put start:crm,不是一个好主意,我认为。

我看到一个例子,即这些文件是通过文件系统从另一个包导入的(成为文件监视运行应用程序的一部分),忽略包根文件夹,我对这种方法感到恐惧,因为它破坏了版本控制。

你们是怎么处理这些问题的?

代码语言:javascript
运行
复制
"/** CRM SCRIPTS */": "",
"start:crm": "npx lerna run start --scope @kovi-cx-frontend/crm",
"build:crm": "npx lerna run build --stream --scope @kovi-cx-frontend/crm",
"test:crm": "npx lerna run test --stream --scope @kovi-cx-frontend/crm",
"lint:crm": "npx lerna run lint --stream --scope @kovi-cx-frontend/crm",
"codegen:crm": "npx lerna run codegen --scope @kovi-cx-frontend/crm",
"start:crm:storybook": "npx lerna run start:storybook --stream --scope @kovi-cx-frontend/crm",
"build:crm:storybook": "npx lerna run build:storybook --stream --scope @kovi-cx-frontend/crm",
EN

回答 1

Stack Overflow用户

发布于 2020-09-22 05:05:11

适当的工具在这里是必须的。

我也有类似的问题:纱线工作空间,几十个包裹,相互依赖,彼此深深地依赖。我的package.json是这样的:

代码语言:javascript
运行
复制
{
  "scripts": {
    "all": "run-s \"generic all\" \"all:apps all\" --",
    "all:apps": "run-p --aggregate-output \"eslint-config {@}\" \"apps1 {@}\" \"apps2 {@}\" --",
    "apps1": "run-s \"apps1:deps {@}\" \"apps1:c {@}\" --",
    "apps1:c": "run-p --aggregate-output \"hatsy:c {@}\" --",
    "apps1:deps": "run-s \"route-match:c {@}\" --",
    "apps2": "run-p --aggregate-output \"siteparts:c {@}\" \"realworld-app:c {@}\" \"examples:c {@}\" --",
    "build": "run-s \"generic build {@}\" \"all:apps build {@}\" --",
    "lint": "run-p --aggregate-output \"generic lint {@}\" \"all:apps lint {@}\" --",
    "test": "run-p --aggregate-output \"generic test {@}\" \"test:apps test {@}\" --",
    "test:apps": "run-p --aggregate-output \"apps1:deps {@}\" \"apps1:c {@}\" \"siteparts:c {@}\" \"realworld-app:c {@}\" --",
    "a-iterable": "run-s \"call-thru {@}\" \"a-iterable:c {@}\" --",
    "a-iterable:c": "run-s -l \"a-iterable:x {@}\" --",
    "a-iterable:x": "yarn workspace @proc7ts/a-iterable",
    "call-thru": "run-s \"primitives:c {@}\" \"call-thru:c {@}\" --",
    "call-thru:c": "run-s -l \"call-thru:x {@}\" --",
    "call-thru:x": "yarn workspace @proc7ts/call-thru",
    "context-values": "run-s \"call-thru {@}\" \"context-values:deps {@}\" \"context-values:c {@}\" --",
    "context-values:c": "run-s -l \"context-values:x {@}\" --",
    "context-values:deps": "run-p --aggregate-output \"a-iterable:c {@}\" \"fun-events:c {@}\" --",
    "context-values:x": "yarn workspace @proc7ts/context-values",
    "delta-set": "run-s \"delta-set:c {@}\" --",
    "delta-set:c": "run-s -l \"delta-set:x {@}\" --",
    "delta-set:x": "yarn workspace @proc7ts/delta-set",
    "eslint-config": "run-s \"eslint-config:c {@}\" --",
    "eslint-config:c": "run-s -l \"eslint-config:x {@}\" --",
    "eslint-config:x": "yarn workspace @proc7ts/eslint-config",
    "fun-events": "run-s \"call-thru {@}\" \"fun-events:c {@}\" --",
    "fun-events:c": "run-s -l \"fun-events:x {@}\" --",
    "fun-events:x": "yarn workspace @proc7ts/fun-events",
    "hatsy": "run-s \"hatsy:deps {@}\" \"hatsy:c {@}\" --",
    "hatsy:c": "run-s -l \"hatsy:x {@}\" --",
    "hatsy:deps": "run-p --aggregate-output \"route-match {@}\" \"http-header-value:c {@}\" --",
    "hatsy:x": "yarn workspace @hatsy/hatsy",
    "http-header-value": "run-s \"http-header-value:c {@}\" --",
    "http-header-value:c": "run-s -l \"http-header-value:x {@}\" --",
    "http-header-value:x": "yarn workspace @hatsy/http-header-value",
    "route-match": "run-s \"primitives:c {@}\" \"route-match:c {@}\" --",
    "route-match:c": "run-s -l \"route-match:x {@}\" --",
    "route-match:x": "yarn workspace @hatsy/route-match",
    "input-aspects": "run-s \"input-aspects:deps0 {@}\" \"input-aspects:deps1 {@}\" \"input-aspects:c {@}\" --",
    "input-aspects:c": "run-s -l \"input-aspects:x {@}\" --",
    "input-aspects:deps0": "run-p --aggregate-output \"call-thru {@}\" \"namespace-aliaser:c {@}\" \"render-scheduler:c {@}\" --",
    "input-aspects:deps1": "run-p --aggregate-output \"a-iterable:c {@}\" \"fun-events:c {@}\" \"delta-set:c {@}\" --",
    "input-aspects:x": "yarn workspace @proc7ts/input-aspects",
    "namespace-aliaser": "run-s \"namespace-aliaser:c {@}\" --",
    "namespace-aliaser:c": "run-s -l \"namespace-aliaser:x {@}\" --",
    "namespace-aliaser:x": "yarn workspace @proc7ts/namespace-aliaser",
    "primitives": "run-s \"primitives:c {@}\" --",
    "primitives:c": "run-s -l \"primitives:x {@}\" --",
    "primitives:x": "yarn workspace @proc7ts/primitives",
    "render-scheduler": "run-s \"render-scheduler:c {@}\" --",
    "render-scheduler:c": "run-s -l \"render-scheduler:x {@}\" --",
    "render-scheduler:x": "yarn workspace @proc7ts/render-scheduler",
    "style-producer": "run-s \"style-producer:deps0 {@}\" \"style-producer:deps1 {@}\" \"style-producer:c {@}\" --",
    "style-producer:c": "run-s -l \"style-producer:x {@}\" --",
    "style-producer:deps0": "run-p --aggregate-output \"call-thru {@}\" \"namespace-aliaser:c {@}\" \"render-scheduler:c {@}\" --",
    "style-producer:deps1": "run-p --aggregate-output \"a-iterable:c {@}\" \"fun-events:c {@}\" --",
    "style-producer:x": "yarn workspace @proc7ts/style-producer",
    "examples": "run-s \"generic {@}\" \"examples:c {@}\" --",
    "examples:c": "run-s -l \"examples:x {@}\" --",
    "examples:x": "yarn workspace @wesib/examples",
    "generic": "run-s \"wesib {@}\" \"generic:deps {@}\" \"generic:c {@}\" --",
    "generic:c": "run-s -l \"generic:x {@}\" --",
    "generic:x": "yarn workspace @wesib/generic",
    "generic:deps": "run-p --aggregate-output \"http-header-value:c {@}\" \"input-aspects:c {@}\" \"style-producer:c {@}\" --",
    "realworld-app": "run-s \"generic {@}\" \"realworld-app:c {@}\" --",
    "realworld-app:c": "run-s -l \"realworld-app:x {@}\" --",
    "realworld-app:x": "yarn workspace @wesib/realworld-app",
    "wesib": "run-s \"wesib:deps {@}\" \"wesib:c {@}\" --",
    "wesib:c": "run-s -l \"wesib:x {@}\" --",
    "wesib:x": "yarn workspace @wesib/wesib",
    "wesib:deps": "run-p --aggregate-output \"context-values {@}\" \"namespace-aliaser:c {@}\" \"render-scheduler:c {@}\" --",
    "siteparts": "run-s \"generic {@}\" \"siteparts:deps {@}\" \"siteparts:c {@}\" --",
    "siteparts:c": "run-s -l \"siteparts:x {@}\" --",
    "siteparts:deps": "run-s \"route-match:c {@}\" \"hatsy:c {@}\" --",
    "siteparts:x": "yarn workspace @surol/siteparts"
  }
}

这绝对不是一条路。

所以我创建了朗兹

package.json现在看起来是这样的:

代码语言:javascript
运行
复制
{
  "scripts": {
    "each": "run-z ...proc7ts ...hatsy ...wesib ...siteparts",
    "each:p": "run-z --bap ...dev-kit ...run-z ...each",
    "+dev-kit/*": "run-z +z ./dev-kit...dev-kit",
    "hatsy/*": "run-z +z ./hatsy// ./hatsy/kit/packages//",
    "proc7ts/*": "run-z +z ./proc7ts//",
    "+run-z/*": "run-z +z ./run-z//",
    "siteparts/*": "run-z +z ./siteparts",
    "wesib/*": "run-z +z ./wesib//",
    "z": "run-z +z:clean +z:test",
    "z:clean": "run-z +each:p/clean",
    "z:test": "run-z +each:p/lint,+each:p/cmd:jest/--runInBand"
  }
}

所以现在我可以:

  • 运行yarn z clean build --all重新生成所有包,
  • 运行yarn z build test --only hatsy来构建和测试包的命名子集,
  • 在特定的包目录中运行yarn build --with-deps以与其依赖关系一起构建它,
  • 允许一些任务并行运行(如linttest),

...and更多。

run-z需要一些时间来学习,但结果是令人满意的。

顺便说一句,你不用安装就可以试一试。例如,以下命令

代码语言:javascript
运行
复制
npx run-z build:crm build:crm:storybook test:crm,lint:crm start:crm,start:crm:storybook

将构建CRM和故事书,然后测试和林特(并行彼此),然后启动CRM和故事书(同样,并行彼此)。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62963921

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档