在launch.json中使用grunt

时间:2016-01-28 15:03:39

标签: visual-studio-code electron

我加载了yeoman generator-meanjs并用Visual Studio Code打开它。 调试器工作得很好。当我点击调试侧栏按钮时a launch.json文件是为我生成的。 launch.json生成器正在查看包含"scripts": { "start": "grunt"}

的package.json

生成器使用grunt启动应用程序。 launch.json文件有 以下内容:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "node",
            "request": "launch",
            "program": "grunt",
            "stopOnEntry": false,
            "args": [],
            "cwd": ".",
            "runtimeExecutable": null,
            "runtimeArgs": [
                "--nolazy"
            ],
            "env": {
                "NODE_ENV": "development"
            },
            "externalConsole": false,
            "sourceMaps": false,
            "outDir": null
        },
        {
            "name": "Attach",
            "type": "node",
            "request": "attach",
            "port": 5858
        }
    ]
}

当我用server.js替换'program' : 'grunt'时,它可以工作。如果我可以将类型更改为grunt,但似乎只支持节点或单声道。

1 个答案:

答案 0 :(得分:7)

我设法通过使用grunt-cli的绝对路径使其工作,如下所示:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Grunt",
            "args": ["build"],            
            "program": "${env.APPDATA}\\npm\\node_modules\\grunt-cli\\bin\\grunt", 
            "stopOnEntry": true,
            "cwd": "${workspaceRoot}"
        }
    ]
}

正如@ L.Butz指出的那样,在较新的vscode版本上,将env.APPDATA替换为env:APPDATA