【发布时间】:2018-02-07 12:27:20
【问题描述】:
TypeScript 在转译时检查整个代码库,即使实际上只有一个文件发生了更改。对于小型项目,这很好,但随着我们的代码库增长,这需要相当长的时间。
在开发过程中,我希望我的单元测试能够快速响应。单元测试应该尽快运行。
不幸的是,我必须在每次运行时等待大约 10-15 秒才能启动单元测试,因为 tsc 需要很长时间才能转换,而其中 60%-80% 用于检查.
这些示例运行只是在一个文件中删除和添加换行符:
yarn tsc v0.27.5
$ "/home/philipp/fancyProject/node_modules/.bin/tsc" "--watch" "--diagnostics"
Files: 511
Lines: 260611
Nodes: 898141
Identifiers: 323004
Symbols: 863060
Types: 302553
Memory used: 704680K
I/O read: 0.17s
I/O write: 0.09s
Parse time: 2.61s
Bind time: 0.95s
Check time: 7.65s
Emit time: 1.45s
Total time: 12.65s
00:35:34 - Compilation complete. Watching for file changes.
00:41:58 - File change detected. Starting incremental compilation...
Files: 511
Lines: 260612
Nodes: 898141
Identifiers: 323004
Symbols: 863060
Types: 302553
Memory used: 1085950K
I/O read: 0.00s
I/O write: 0.04s
Parse time: 0.68s
Bind time: 0.00s
Check time: 12.65s
Emit time: 1.36s
Total time: 14.69s
00:42:13 - Compilation complete. Watching for file changes.
00:42:17 - File change detected. Starting incremental compilation...
Files: 511
Lines: 260611
Nodes: 898141
Identifiers: 323004
Symbols: 863060
Types: 302553
Memory used: 1106446K
I/O read: 0.00s
I/O write: 0.12s
Parse time: 0.32s
Bind time: 0.01s
Check time: 9.28s
Emit time: 0.89s
Total time: 10.50s
00:42:27 - Compilation complete. Watching for file changes.
不知道有没有办法告诉打字稿:
只要一切正常,尽快将 JavaScript 转储到磁盘。
我想首先确保我的单元测试通过,以便有一个快速的反馈循环。
而且由于我的 IDE 已经在我正在处理的文件中处理类型检查,所以无论如何我在检查转译时很少出错。如果有一个大问题,我的单元测试应该会发现它们。
在构建项目时,我只会使用带有检查的经典 tsc。正如我所说,这仅用于开发和快速反馈循环。
【问题讨论】:
-
@AlekseyL。您能否将您的评论扩展为有关如何使用 ts-loader 的更多详细信息的答案?
标签: performance typescript configuration tsc