typescript - TypeScript:同时监视和编译多个目录(monorepo)
问题描述
我一直在网上搜索解决方案,但没有发现任何有价值的东西。基本上,我正在寻找一种工具或某种方式来同时在多个目录中启动 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 项目引用与 一起使用tsc -b --watch
,尽管该功能非常新并且存在一些错误(截至 2018 年 9 月)。
推荐阅读
- asp.net - 发送到主视图时 ViewModel 属性为 NULL - Asp.Net Core MVC
- java - 是我导师的界面有问题吗?
- app-store - 一个帐户拥有多个 App Store 页面
- java - 货币转换器 - 为什么我的 for 循环在 switch 中不起作用?当我运行我的代码时,只有第一个 for 循环有效
- vba - 在 VBA 用户窗体中,退出文件时触发哪个事件
- java - 如何将空列表发送到 IN 子句
- model - Model.all 的替代方案 - Model.where(condition)
- java - JavaFX Listview - 双击禁用编辑?
- python - 如何正确绘制多边形集合(stl 文件)?
- r - 在 r 中找到接近某个值的倍数