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

标签 typescript npm monorepo

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

我有一个带有作用域 NPM 包(@test/one、@test/two、@test/three 等)的 monorepo,我想同时观看/编译所有这些包。

看起来 TS 不支持这个,而且实际上也没有任何工具可以做到这一点。我找到的最接近的东西是 nodemon,我可以让它同时监视多个目录,但它只支持在单个位置执行脚本/二进制文件,而我需要它在每个监视的目录中执行 'tsc'。

我能用 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-*"
  },

有什么想法吗?

最佳答案

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

关于TypeScript:同时观察和编译多个目录(monorepo),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52467442/

相关文章:

javascript - Node.js 'require' 不需要命名空间即可访问其他文件

css - 如何使用UnCSS

yarnpkg - Yarn 工作区不构建本地依赖性

javascript - lerna 链接与 lerna Bootstrap

javascript - 我的服务仅在我的 ngx 传单 map 上显示最后一个 json 元素标记

typescript - 删除编译输出中的引用标签

angular - typescript - 使用 "@"符号导入自定义类

reactjs - RTK查询错误: could not find react-redux context value; please ensure the component is wrapped in a <Provider>

angular - 代码块内的jsdoc @字符

angular - Ionic 2/Angular 2 中的全局函数