如何调试Gulp任务? [英] How to debug a Gulp task?

查看:160
本文介绍了如何调试Gulp任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用调试器(如Google Chrome调试器)调试我的 gulpfile.js 中定义的gulp任务,逐行执行任务的代码? p>

解决方案

使用Node.js版本6.3+调试已经变得简单得多,使用 标志。



调试名为 build的gulp任务


  1. 找出你的gulp可执行文件的存在位置。如果gulp在本地安装,那将在 node_modules / .bin / gulp 中。否则,在终端上,在Linux / Mac上运行,或者在Windows上运行其中gulp 找到它。 p>


  2. 运行 node --inspect --debug-brk ./node_modules/.bin/gulp build 。如果需要,更换gulp的路径。


  3. 使用Chrome浏览到打印到控制台的URL。它看起来像 chrome-devtools://devtools/remote/serve_file/@xxx/inspector.html?experiment = true& v8only = true& ws = localhost:9229 / node


- debug-brk 标志用于立即暂停代码执行。这可以让您有机会在任务完成之前打开浏览器并设置断点。


How do I debug a gulp task defined in my gulpfile.js with a debugger such as the Google Chrome debugger, stepping through the task's code line by line?

解决方案

With Node.js version 6.3+ debugging has been made much simpler with the use of the --inspect flag.

To debug a gulp task named build:

  1. Find out where your gulp executable lives. If gulp is installed locally, this will be at node_modules/.bin/gulp. Otherwise, in a terminal, run which gulp on Linux/Mac or where gulp on Windows to find it.

  2. Run node --inspect --debug-brk ./node_modules/.bin/gulp build. Replace the path to gulp if required.

  3. Use Chrome to browse to the URL that gets printed to the console. It looks like chrome-devtools://devtools/remote/serve_file/@xxx/inspector.html?experiments=true&v8only=true&ws=localhost:9229/node

The --debug-brk flag is used to pause code execution immediately. This gives you a chance to open up the browser and set breakpoints before the task finishes.

这篇关于如何调试Gulp任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆