在launch.json中使用grunt

mat*_*key 6 electron visual-studio-code

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

生成器使用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
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

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

dar*_*ong 8

我设法通过使用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}"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

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

  • 我注意到我的本地版本的VS Code(V 1.13.1,Windows)抱怨"env.APPDATA"并且期望"env:APPDATA".所以改变了.to:在我的电脑上足以完成这项工作.谢谢! (3认同)
  • 感谢 @darksoulsong 帮助我设置了 launch.json (2认同)