如何调试Gulp任务? [英] How to debug a Gulp task?
问题描述
如何使用调试器(如Google Chrome调试器)调试我的 gulpfile.js
中定义的gulp任务,逐行执行任务的代码? p>
使用Node.js版本6.3+调试已经变得简单得多,使用
标志。
调试名为 build的gulp任务
:
-
找出你的gulp可执行文件的存在位置。如果gulp在本地安装,那将在
node_modules / .bin / gulp
中。否则,在终端上,在Linux / Mac上运行,或者在Windows上运行其中gulp
找到它。 p> -
运行
node --inspect --debug-brk ./node_modules/.bin/gulp build
。如果需要,更换gulp的路径。 -
使用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
:
Find out where your gulp executable lives. If gulp is installed locally, this will be at
node_modules/.bin/gulp
. Otherwise, in a terminal, runwhich gulp
on Linux/Mac orwhere gulp
on Windows to find it.Run
node --inspect --debug-brk ./node_modules/.bin/gulp build
. Replace the path to gulp if required.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屋!