lerna run --parallel 不适用于汇总表

Sam*_*ina 0 rollupjs lerna yarn-workspaces

背景:

我有一个带有两个包的纱线工作区的 lerna monorepo。我使用 rollup 作为打包器。

包/模块1/package.json:

{
  scripts: {
    "watch": "rollup -c rollup.config.js --watch",
    "build": "NODE_ENV=production && rollup -c rollup.config.js"
  }
}
Run Code Online (Sandbox Code Playgroud)

包/module2/package.json:

{
  scripts: {
    "watch": "rollup -c rollup.config.js --watch",
    "build": "NODE_ENV=production && rollup -c rollup.config.js"
  }
}
Run Code Online (Sandbox Code Playgroud)

预期行为:

  1. lerna run build将为build每个包运行脚本。
  2. lerna run watch将以watch监视模式运行每个包的脚本。

当前行为:

  1. lerna run build按预期工作。该build脚本对这两个包都可以正常运行。
  2. lerna run watch 只是挂在那里:
lerna notice cli v3.13.1
lerna info Executing command in 2 packages: "yarn run watch"
[[just hangs here]]
Run Code Online (Sandbox Code Playgroud)

我试过了lerna run --parallel watch这只运行一次。在汇总完成后退出。换句话说,它似乎从来没有在看。

lee*_*rob 6

我相信您正在寻找的命令是lerna exec. 这将在 Monorepo 中的每个包上运行传递给它的任何命令。

lerna exec --parallel -- yarn build
Run Code Online (Sandbox Code Playgroud)

如果每个包都有相同的构建步骤,您可以将其抽象到顶层,package.json如下所示:

lerna exec --parallel -- rollup -c=rollup.config.js
Run Code Online (Sandbox Code Playgroud)

这将进入每个包并运行该汇总命令。


资料来源: