【问题标题】:Is it possible to disable type checks when transpiling typescript via tsc to speed up transpiling?通过 tsc 转译 typescript 以加快转译速度时,是否可以禁用类型检查?
【发布时间】: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。正如我所说,这仅用于开发和快速反馈循环。

【问题讨论】:

  • 带有ts-loader 的Webpack 仅重新编译已更改的文件和依赖于已更改文件的文件。 Here你可以找到示例配置。
  • @AlekseyL。您能否将您的评论扩展为有关如何使用 ts-loader 的更多详细信息的答案?

标签: performance typescript configuration tsc


【解决方案1】:
  1. 开始使用 WebPack
  2. 添加awesome-typescript-loader
  3. 将设置中的transpileOnly 设置为true

您还可以更改其他参数,以提高速度:ignoreDiagnosticsforceIsolatedModules 等。

【讨论】:

  • 能否请您添加必要配置更改的更深入版本? (我也已经为 ts 文件准备了 webpack,并且很难找出要添加的内容以及它如何影响内容。
  • 您不了解 WebPack 或 awesome-typescript-loader 文档的哪一部分?
猜你喜欢
  • 1970-01-01
  • 2018-06-30
  • 1970-01-01
  • 2013-05-29
  • 2018-08-20
  • 1970-01-01
  • 2020-03-01
  • 1970-01-01
  • 2011-06-15
相关资源
最近更新 更多