VSCODE V0.7.0 任务快捷键
Gulp、Grunt 和 Jake 仅在打开文件夹的根目录中存在相应文件时才会被自动检测。对于下面的 Gulp 任务,子任务 optimize 用于 serve-build,inject 用于 serve-dev 、运行额外的子任务等等……这个过程使两个顶级任务可用于构建和开发工作流。
gulpfile.js
//automate build node server start and restart on changes
gulp.task('serve-build', ['optimize'], function () {
serve(false /* is Build */);
});
//automate dev node server start and restart on changes
gulp.task('serve-dev', ['inject'], function () {
serve(true /* is Dev */);
});
上述 Gulp 任务将被 VSCode 自动检测到,其他许多任务也是如此。
但是,您可以在 tasks.json 文件中为 TEST 和 BUILD 手动定义两个键盘快捷键任务。随后,您可以分别使用 CTRL-SHFT-T 和 CTRL-SHFT-B 运行 TWO 顶级任务。
tasks.json
{
"version": "0.1.0",
"command": "gulp",
"isShellCommand": true,
"args": [
"--no-color"
],
"tasks": [
{
"taskName": "serve-dev",
"isBuildCommand": false,
"isTestCommand": true,
"showOutput": "always",
"args": []
},
{
"taskName": "serve-build",
"isBuildCommand": false,
"isTestCommand": true,
"showOutput": "always",
"args": []
}
注意 isTestCommand 和 isBuildCommand 这两个属性。这些直接映射到 CTRL-SHFT-T 和 CTRL-SHFT-B。因此,您可以根据需要将任何任务映射到这些键盘快捷键。如果您有多个将这些属性设置为 true 的任务,VSCode 将使用 tasks.json 文件中的第一个任务。
如果任务结构和嵌套正确,您应该能够使用两个键盘快捷键构建您的工作流程,并避免让 VSCode 每次都通过 CTRL+SHFT+P 菜单枚举您的任务。
抑制任务名称
有一个全局属性 suppressTaskName 可以在 tasks.json 中使用。此属性控制是否将任务名称作为参数添加到命令中。
我不确定这是否有帮助,但很高兴知道。看起来这是一种将内置参数传递给任务运行器的方法。更多在这里Task Appendix。我没有机会对此进行测试以确定与传统 "args:[]" 属性有何不同。我知道在 v0.7.0 之前,args 存在问题,即在使用时参数和任务名称必须颠倒。见accept args the task name and args had to be reversed
showOutput 属性在有和没有 problemMatcher 属性的情况下也可以用于在 VSCode 输出窗口中显示输出。
{
"version": "0.1.0",
"command": "gulp",
"showOutput": "silent"
"isShellCommand": true,
"args": [
"--no-color"
],
"tasks": [
{
"taskName": "gulp-argument",
"suppressTaskName": true,
...
},
{
"taskName": "test",
"args": [],
"isBuildCommand": true,
"showOutput": "always",
"problemMatcher": "$msCompile"
...
},
{
}....
]
}
以下是一些关于 VSCode 任务的其他 StackOverFlow 主题:
Define multiple tasks in VSCode
Configure VSCode to execute different task
链接