如何同时运行多个VSCode任务?

14
例如,同时运行一个 TypeScript 监视任务和一个 Gulp 任务(不使用终端)。
3个回答

12

请参考运行多个任务。您可以在2.0.0版本的tasks.json中使用“dependsOn”关键字。以下是来自上述链接的示例:

{
    "version": "2.0.0",
    "tasks": [
        {
            "taskName": "Client Build",
            "command": "gulp",
            "args": ["build"],
            "isShellCommand": true,
            "options": {
                "cwd": "${workspaceRoot}/client"
            }
        },
        {
            "taskName": "Server Build",
            "command": "gulp",
            "args": ["build"],
            "isShellCommand": true,
            "options": {
                "cwd": "${workspaceRoot}/server"
            }
        },
        {
            "taskName": "Build",
            "dependsOn": ["Client Build", "Server Build"]
        }
    ]
}

显然,这仍然是初步版本?除非我错过了,否则很难找到文档。但是我测试过它并且它有效。它是在vscode 1.10中添加的。


12

我使用类似这样的tasks.json来同时运行两个监视任务:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Watch all",
            "dependsOn": [
                "Watch package 'core'",
                "Watch package 'ui'"
            ],
            "dependsOrder": "parallel",
            "group": "build",
            "problemMatcher": [
                "$tsc-watch"
            ],
            "isBackground": true
        },
        {
            "label": "Watch package 'core'",
            "type": "typescript",
            "tsconfig": "packages/core/tsconfig.json",
            "option": "watch",
            "problemMatcher": [
                "$tsc-watch"
            ],
            "group": "build"
        },
        {
            "label": "Watch package 'ui'",
            "type": "typescript",
            "tsconfig": "packages/ui/tsconfig.json",
            "option": "watch",
            "problemMatcher": [
                "$tsc-watch"
            ],
            "group": "build"
        }
    ]
}
当您在VSCode中打开“构建菜单”时,可以选择运行两个单独的监视任务或“全部监视”任务,后者会运行其他两个任务。我想您可以轻松地将其中一个监视任务替换为gulp任务。

正是我所需要的。谢谢! - maxime1992

-1

VS Code内置了一个任务运行器,您可以配置多个任务。

在VS Code中,按下Ctrl+Shift+P并搜索“Tasks: Configure Task Runner”。将创建一个tasks.json文件。以下是一些示例代码,显示如何配置多个任务。

{ "version": "0.1.0", "tasks": [ { "taskName": "tsc", "command": "tsc", "args": ["-w"], "isShellCommand": true, "isBackground": true, "problemMatcher": "$tsc-watch" }, { "taskName": "build", "command": "gulp", "args": ["build"], "isShellCommand": true } ] }

通过按下Ctrl+Shift+P并搜索“Task: Run task”来运行任务。

请参阅更多文档https://code.visualstudio.com/docs/editor/tasks


5
似乎在这里没有回答“multiple”部分。 - Craig Brett

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接