请参考运行多个任务。您可以在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中添加的。
我使用类似这样的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任务。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”来运行任务。