Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run grunt task with target/argument in VSCode

I have VSCode version 1.18.1, and this in my Gruntfile.js

grunt.registerTask('release', 'Release process', function(target) {
    ...
}

The target is there so that I can run grunt release:one or grunt release:two. However, I can't figure out how to make VSCode run the task with the one|two target.

This is tasks.json file VSCode created with Grunt task auto detected.

{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
    {
        "type": "grunt",
        "task": "release",
        "problemMatcher": [],
        "label": "Release Process",
        "group": {
            "kind": "build",
            "isDefault": true
        }
    }
]
}

If I put release:one to the task attribute of the tasks.json file, VSCode will complain with something like

Error: The grunt task detection didn't contribute a task for the following configuration:

Anyone has done something similar to this? Can you please guide me on how to do it?

Thank you!

like image 582
Ngoc Pham Avatar asked Nov 20 '17 15:11

Ngoc Pham


People also ask

How do I pass a parameter to a grunt task?

The Grunt option API is for sharing parameters across multiple tasks and accessing parameters set on the command line. An example would be a flag to target whether your build is for development or staging. On the command line: grunt deploy --target=staging would cause grunt. option('target') to return "staging" .


1 Answers

The way I solved this issue myself was by creating a Task of type shell instead, and putting in the full command. For example, you can do following:

{ "version": "2.0.0", "tasks": [ { "type": "shell", "label": "Release one", "command": "grunt release:one", "problemMatcher": [], }, { "type": "shell", "label": "Release two", "command": "grunt release:two", "problemMatcher": [], } ] }

like image 182
Gideon Pyzer Avatar answered Oct 23 '22 03:10

Gideon Pyzer