How to run a Gulp task with a keyboard shortcut

和自甴很熟 提交于 2019-12-23 03:30:07

问题


I want to run the default Gulp task with VS code by using the inbuilt feature to do so. My tasks.json is as follows:

{ "version": "2.0.0", "tasks": [ { "type": "gulp", "task": "default", "problemMatcher": [] } ] }

When I run the task with the keyboard shortcut(my keybindings are already modified to run the task), I get an options menu with all the list of the Gulp tasks. To actually run the gulp command, I have to select the 'gulp:default' task from the list. How can I run the task without having to see the list and selecting the 'gulp:default' option?


回答1:


In .vscode/tasks.json in the workSpaceRoot:

Try the following - the main thing you need is a "label" to use as an argument in your keybinding - the label can be whatever you want:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Your task label",
            "command": "gulp",
            "args": ["default"],
            "type": "shell",
             "options": {
                "cwd": "${workspaceRoot}"
            }
            "problemMatcher": []
        }
    ]
}

Keybinding:

    { "key": "shift+escape",  
      "command": "workbench.action.tasks.runTask", 
      "args": "Your task label here"
    },



回答2:


press ctlr+shift+B to run the task

tasks.json

{ "tasks": [ { "type": "gulp", "taskName": "gulp", "command": "gulp", "args": [ "html", "css" ], "isShellCommand": true, "isBuildCommand": true } ] }

this will run gulp css and gulp html



来源:https://stackoverflow.com/questions/49047352/how-to-run-a-gulp-task-with-a-keyboard-shortcut

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!