Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 489
Richard Collette Avatar asked Feb 08 '15 00:02

Richard Collette


People also ask

How do I run Gulpfile in Visual Studio?

Run a Gulp Task in Visual Studio Code Type "Run Task" and select it, which will bring up a list of tasks configured in Gulp. Choose the Gulp Task you want to run! Most of your Gulp Tasks will probably be automated using gulp watch, but manual Gulp Tasks can easily be run within Visual Studio Code.

How do I use task runner Explorer?

Configuring Visual Studio Task Runner to Execute A Task When the Project is Opened. If you have never used or opened the built in task runner it is simple, press Alt + Shift + Backspace or select it from the other windows list from the View menu. You should see the task runner window at the bottom of Visual Studio.


2 Answers

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.

like image 181
Byron Avatar answered Oct 04 '22 10:10

Byron


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.

like image 43
Andrew Arnott Avatar answered Oct 04 '22 08:10

Andrew Arnott