How can I debug gulpfile.js when running it with Visual Studio Task Runner Explorer?

时间秒杀一切 提交于 2019-12-04 15:37:19

问题


How can I debug gulpfile.js when running it with Visual Studio Task Runner Explorer? Or is there another way gulp may be launched with visual studio such that gulpfile.js may be debugged? I am aware of node-inspector but want to see if there is something native to Visual Studio.


回答1:


I know that you may expect a better way of doing this but he way I currently do it is by using plain

console.log() statements inside the gulpfile.js

That way I can inspect the variables and try and spot any logic errors.




回答2:


Define a .vscode\launch.json file in the folder you "Open Folder" to in VS Code with this content:

{
    // Use IntelliSense to learn about possible Node.js debug attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "cwd": "${workspaceRoot}/src/node",
            "name": "Gulp package node",
            "program": "${workspaceRoot}/src/node/node_modules/gulp/bin/gulp.js",
            "args": [
                "package" // replace this with your gulp task name
            ]
        }
    ]
}

You'll obviously want to replace the task name and the path to your code in the above.

Then you can just hit "Go" in VS Code and it will launch gulp with the debugger attached.



来源:https://stackoverflow.com/questions/28389037/how-can-i-debug-gulpfile-js-when-running-it-with-visual-studio-task-runner-explo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!