如何在VS Code的tasks.json中为TypeScript编译任务启用--incremental标志?
解决方法
有两种方式可以实现等价于tsc --watch --incremental的任务配置:
方式一:在tasks.json中添加命令行参数
你可以通过args字段直接追加--incremental参数,有两种写法:
写法1:替换option为args包含所有参数
{ "version": "2.0.0", "tasks": [ { "label": "build", "type": "typescript", "tsconfig": "tsconfig.json", "args": ["--watch", "--incremental"], "group": { "kind": "build", "isDefault": true } } ] }
写法2:保留watch选项,追加incremental参数
{ "version": "2.0.0", "tasks": [ { "label": "build", "type": "typescript", "tsconfig": "tsconfig.json", "option": "watch", "args": ["--incremental"], "group": { "kind": "build", "isDefault": true } } ] }
方式二:在tsconfig.json中启用增量编译(推荐)
更简洁的方式是直接在tsconfig.json的compilerOptions里添加"incremental": true,这样不管是通过tasks运行还是直接执行tsc --watch,都会自动启用增量编译,无需在命令行或tasks中额外加参数:
{ "compilerOptions": { "incremental": true, // 你的其他编译配置... } }
内容的提问来源于stack exchange,提问作者birgersp
相关产品推荐
相关产品推荐

