我使用以下 tasks.json 文件来运行多个 TypeScript 构建方案。我在每个文件夹中放了一个 tsconfig.json 文件,这样我就可以单独调整每个文件夹的输出。只需确保您禁止显示任务名称,因为它会尝试将其放入命令字符串中。
{
"version": "0.1.0",
"command": "tsc",
"showOutput": "always",
"isShellCommand": true,
"args": [],
"windows": {
"command": "tsc",
"showOutput": "always",
"isShellCommand": true
},
"tasks": [
{
"taskName": "Build the examples",
"suppressTaskName": true,
"isBuildCommand": false,
"args": ["-p", "./source/examples", "--outDir", "./script/examples"],
"problemMatcher": "$tsc"
},
{
"taskName": "Build the solution",
"suppressTaskName": true,
"isBuildCommand": false,
"args": ["-p", "./source/solution", "--outDir", "./script/solution"],
"problemMatcher": "$tsc"
}
]
}
这是文件夹结构的样子,其中 /script 是输出根目录,/source 是输入根目录。两个文件夹都引用 /typingd 文件夹和 /typings 文件夹中的类型声明。 TypeScript 在某种程度上仅限于在外部引用中使用相对路径,因此如果这些文件夹结构相似,它有助于简化事情。
哦,是的,如果您将它们标记为非构建并覆盖构建键以从列表中选择特定任务,则可以更轻松地有选择地启动它们,就像这样..
// Place your key bindings in this file to overwrite the defaults
[
{ "key": "ctrl+shift+b", "command": "workbench.action.tasks.runTask" }
]
更新:如果你愿意,你总是可以完全无赖。可能有更好的方法来处理参数,但目前这对我在 OSX 下有效。
{
"version": "0.1.0",
"isShellCommand": true,
"linux": { "command": "sh", "args": ["-c"] },
"osx": { "command": "sh", "args": ["-c"] },
"windows": { "command": "powershell", "args": ["-Command"] },
"tasks": [
{
"taskName": "build-models",
"args": ["gulp build-models"],
"suppressTaskName": true,
"isBuildCommand": false,
"isTestCommand": false
},
{
"taskName": "run tests",
"args": ["mocha ${workspaceRoot}/test"],
"suppressTaskName": true,
"isBuildCommand": false,
"isTestCommand": false
}
]
}