我正在使用带有 Typescript 1.5.4 和 Resharper 9 的 Visual Studio 2015
这是错误的场景:
- 我有大约 180 个 typescript 文件
- 我更改单个 .ts 文件
- VS 显示消息“XXX.ts 文件生成完成。剩余文件仍在编译中”
- 之后我所有的 .ts 文件都被编译成 .js
- 这些 .js 文件中有两处发生了变化:格式略有不同,并且删除了对 .js.map 的引用
- 当我构建整个项目时,会再次生成 .js 文件,但会使用原始格式并提供指向 .js.map 的链接
这很烦人,因为它在 Git 中产生了太多噪音 它阻止我直接在浏览器中调试 typescript 文件。 (因为缺少 .js.map 文件)
期望的行为当然是在保存时编译唯一更改的 .ts 文件。怎么做?
似乎 R# 与此无关,因为它在禁用 R# 的情况下继续发生。
------------更新------------
我已经尝试更新到 Typescript 1.6 版。
PATH 变量指向 C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.4\
所以我将其更新为指向 1.6
所以当我现在输入 tsc -v
它说message TS6029: Version 1.6.2
但由于历史原因(我从事的项目大约有 2 年历史)我必须使用版本 1.4
在 VisualStudio 中。所以在 .csproj 中是 <TypeScriptToolsVersion>1.4</TypeScriptToolsVersion>
在此更改之后 compile on safe
完全停止工作。
现在我必须重建整个解决方案:(
最佳答案
Visual Studio 似乎不支持 watch 模式(即增量编译):
Just to be clear,
--watch
does work on Windows if you're using node.js/io.js, but the tsc.exe program distributed with VS does not support it; you still have Compile on Save for similar functionality anyhow.
https://github.com/Microsoft/TypeScript/issues/2375#issuecomment-100812347
I'm not sure why this was closed. Supporting --watch for our tsc.exe host would both be possible and desirable. Right now the limiting factor is that our tsc.exe host is a bit of ugly C++, that uses some ancient COM interfaces for Chakra that we haven't spent much effort on. Our options are: [...]
https://github.com/Microsoft/TypeScript/issues/2375#issuecomment-100949019
作为解决方法,您可以运行
tsc --watch
在tsconfig.json
所在的文件夹中?
编辑: https://github.com/Microsoft/TypeScript/issues/5638 - Visual Studio 2015 在更改单个文件时编译所有 typescript 文件
Starting with VS 2015 RTM, Compile-on-Save, every time you save a file we need to generate all files in the project to ensure consistent output. We have got numerous issues related to inconsistent output when saving files in different orders. Building all files is the only way we can guarantee correct and consistent output given all the language constructs and how they interact across files (e.g. namespaces/internal modules can be augmented, and that affects the shape of emitted code, also const enms are in lined as constants, etc..).
关于javascript - 更改单个文件时,Visual Studio 2015 会编译所有 typescript 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32398515/