在VSCode中使用目标/参数运行grunt任务

时间:2017-11-20 15:22:07

标签: gruntjs visual-studio-code

我有VSCode版本1.18.1,这在我的Gruntfile.js

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

target就可以运行grunt release:onegrunt release:two。但是,我无法弄清楚如何使VSCode使用one|two目标运行任务。

这是tasks.json文件VSCode创建时自动检测到Grunt任务。

{
// 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
        }
    }
]
}

如果我将release:one放入task文件的tasks.json属性,VSCode会抱怨类似

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

有人做过类似的事吗?你能指导我怎么做吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

我自己解决这个问题的方法是创建一个shell类型的任务,然后输入完整的命令。例如,您可以执行以下操作:

{ "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": [], } ] }