You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 02:57:15