【问题标题】:How can I debug gulpfile.js when running it with Visual Studio Task Runner Explorer?使用 Visual Studio Task Runner Explorer 运行 gulpfile.js 时,如何调试它?
【发布时间】:2015-04-07 23:14:57
【问题描述】:

在使用 Visual Studio Task Runner Explorer 运行 gulpfile.js 时,如何调试它?或者是否有另一种方式可以使用 Visual Studio 启动 gulp,以便可以调试 gulpfile.js?我知道节点检查器,但想看看是否有 Visual Studio 原生的东西。

【问题讨论】:

标签: node.js visual-studio gulp


【解决方案1】:

在 VS Code 中“打开文件夹”的文件夹中定义一个 .vscode\launch.json 文件,内容如下:

{
    // 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
            ]
        }
    ]
}

您显然希望替换上面代码中的任务名称和路径。

然后你可以在 VS Code 中点击“Go”,它会启动 gulp 并附加调试器。

【讨论】:

  • 操作要求的是 VS 而不是代码。
  • 那么,有没有办法在 Visual Studio 2017 中调试 gulpfile.js?有没有办法在断点处停止?如果没有,有没有办法查看 console.log 输出?
【解决方案2】:

我知道您可能希望有更好的方法来做到这一点,但我目前这样做的方法是使用普通的

gulpfile.js 中的

console.log() 语句

这样我可以检查变量并尝试发现任何逻辑错误。

【讨论】:

  • 我希望有更好的东西,但感谢您的回答:)。
  • 我也是,在 WebStorm 中我可以右键单击任务并选择运行或调试。如果我选择调试,它会在 gulpfile 中命中我的断点。
  • 这个答案仍然是最新的吗? VS NodeJS 工具发布了吗?
  • VS Code 可以用来调试它。 hansrwindhoff.wordpress.com/2015/05/05/…
  • 您是否已在“输出”窗口中切换到相应的“显示输出自”?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-02-02
  • 1970-01-01
  • 1970-01-01
  • 2020-08-19
  • 2020-10-24
  • 1970-01-01
  • 2018-03-16
相关资源
最近更新 更多