Search code examples
gulpvisual-studio-code

How to run a Gulp task with a keyboard shortcut


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?


Solution

  • 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"
        },