如何在VSCode中运行Grunt任务?

AJ *_*ris 13 gruntjs visual-studio-code

标题说明了一切.我仍然使用Grunt,虽然感觉我应该使用Gulp.

尽管如此,我不想使用alt-tabbing到CMD窗口,而是想使用调色板或快捷键来启动一些Grunt任务.阅读文档,看起来我需要编写一个json任务.什么???这就像编写Grunt任务来运行Grunt任务一样.

还有其他人已经为运行Grunt写了一个通用的VSCode任务吗?

编辑:感谢接受的答案,这是我正在运行的:

{
    "version": "0.1.0", 
    "command": "grunt",
    "isShellCommand": true,
    "tasks": [{
        "taskName": "default"
    },{
        "taskName": "stage"
    },{
        "taskName": "dist"
    }]
}
Run Code Online (Sandbox Code Playgroud)

我打开调色板,看到默认,舞台,dist.不确定这是否是最好的方式,但它到目前为止工作.绝对有改进的余地.

jlu*_*una 13

对VSC的最新更新已自动检测grunt(和gulp任务),因此您现在可以使用cmd+p然后键入task(注意结尾处的空间),VSC将显示要运行的可用任务.

这是它的外观

更多信息请访问:https://code.visualstudio.com/Docs/editor/tasks


小智 5

在默认tasks.json文件中,您只需修改用于grunt的gulp示例.在我当前的项目中,我只需要grunt在根目录中运行,所以我看起来像这样:

{
    "command": "grunt",
    "isShellCommand": true
}
Run Code Online (Sandbox Code Playgroud)

您还可以修改现有tasks选项以添加要在构建中运行的特定任务.

  • 应该注意的是,`isShellCommand`在1.14中已被弃用.相反,你应该用`"type":"shell"来切换它. (3认同)