Chirag Bhansali
Chirag Bhansali

Reputation: 2542

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?

Upvotes: 2

Views: 2052

Answers (2)

Mark
Mark

Reputation: 182591

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

Upvotes: 4

Sahin Erbay
Sahin Erbay

Reputation: 1014

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

Upvotes: 0

Related Questions