TypeScript:同时观看和编译多个目录(monorepo)

时间:2018-09-23 15:10:55

标签: typescript npm monorepo

我一直在网上寻找解决方案,但没有发现任何有价值的东西。基本上,我正在寻找一种工具或某种方式来同时在多个目录中启动TypeScript文件监视/编译。

我有一个带有范围内NPM软件包(@ test / one,@ test / two,@ test / three等)的monorepo,我想同时观看/编译所有这些软件包。

TS似乎不支持此功能,并且实际上也没有任何工具可以做到这一点。我发现最接近的是nodemon,我可以使其一次监视多个目录,但是它仅支持在单个位置执行脚本/二进制文件,而我需要它在更改时在每个监视的目录中执行'tsc'。 / p>

我可以用nodemon做的最好的事情如下,但这当然不是一个很好的方法,因为即使只有一个更改,它也可以编译所有软件包:

npx nodemon --watch test-shared-api --watch test-shared-redux --watch test-shared-types -e js,ts,jsx,tsx --exec "npx tsc --build test-shared-api/tsconfig.json && npx tsc --build test-shared-types/tsconfig.json && npx tsc -build test-shared-redux/tsconfig.json"

同时,我可以在package.json中执行以下操作,这虽然更好,但仍然可以做得更好:

  "scripts": {
"ts-watch-shared-types": "tsc -p packages/@test-shared/test-shared-types/tsconfig.json -w",
"ts-watch-shared-api": "tsc -p packages/@test-shared/test-shared-api/tsconfig.json -w",
"ts-watch-shared-redux": "tsc -p packages/@test-shared/test-shared-redux/tsconfig.json -w",
"ts-shared-watch": "concurrently -k -n w: npm:ts-watch-shared-*"
  },

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

您可以尝试将TypeScript project referencestsc -b --watch一起使用,尽管该功能是非常新的并且有一些错误(截至2018年9月)。