如何使用 Node Tools for Visual Studio 调试 Gulp 任务? [英] How can I debug Gulp tasks using Node Tools for Visual Studio?
问题描述
我最近安装了
你可以.右键单击 Node 项目,选择 Properties,然后如下配置您的应用程序(在图像中,default
是您要运行的 Gulp 任务).
替代方法:
- 在终端中,在 gulpfile 所在的目录中,运行
node --debug=44331 --debug-brk ../node_modules/gulp/bin/gulp.js default
.就我而言,default
是我要运行/调试的任务名称. - 在 Visual Studio 中,转到
调试 |附加到进程
.选择Node.js Remote debugging
作为 Transport,并在限定符中选择localhost:44331
.按 Enter 键,您应该会看到 Node 进程出现在列表中.点击附加
.
瞧,断点被命中了.
有几点需要注意:
- 如果您得到类似
无法附加到进程的信息.错误 0x80004005
使用不同的端口.我无法让它与端口 5858 一起工作. - 第一次附加到进程时它可能不起作用(请参阅我之前的屏幕截图我是如何获得
ECANCELED
的?).再试一次.
I recently installed NodeJS Tools for Visual Studio which touts support for Node environments in VS. Notably, it has the ability to set debug breakpoints from the IDE.
It's unclear to me if it is possible to set breakpoints when debugging Gulp tasks. The Task Runner has the ability to detect the Gulp task and output console.log
statements to a window, but I haven't found a better means of debugging.
I found this post from a while back: How can I debug gulpfile.js when running it with Visual Studio Task Runner Explorer? However, this post doesn't involve NodeJS Tools for VS. So, I'm re-asking the question to take that plugin into consideration.
You can. Right-click the Node project, select Properties, and configure your app as follows (in the image, default
is the Gulp task that you want to run).
Alternative method:
- In a terminal, and in the directory where the gulpfile is, run
node --debug=44331 --debug-brk ../node_modules/gulp/bin/gulp.js default
. In my case,default
is the task name I want to run/debug. - In Visual Studio, go to
Debug | Attach to Process
. SelectNode.js Remote debugging
as Transport, and in the qualifier selectlocalhost:44331
. Press enter and you should see the Node process appear in the list. ClickAttach
.
Voila, the breakpoints are hit.
A couple of things to notice:
- If you get something like
Unable to attach to process. Error 0x80004005
use a different port. I couldn't get it to work with port 5858. - It may not work the first time you attach to the process (see my previous screenshot how I got
ECANCELED
?). Try again.
这篇关于如何使用 Node Tools for Visual Studio 调试 Gulp 任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!