首页 > 如何调试gulpfile.js文件

如何调试gulpfile.js文件

请问gulpfile.js文件如何能在chrome下运行,这样就可以打断点调试了。因为代码是别人写的。也没什么注释所以想调试一下看看是怎么运行的。


gulpfile.js 是用gulp命令来运行的,默认加载这个文件,gulp有一个参数:--gulpfile,可以指定gulpfile.file文件的路径。然后node your_node_modules_path/.bin/gulp.js --gulpfile your_gulpfile.js 来运行。然后再加上node本身的debug参数就可以debug了;

如果webstorm来开发的话,debug就更简单了,直接在webstorm就可以debug了,都不用chrome了。


如 @芝麻飞来 同学所说,gulp 其实也是 node 程序,如何debug node 就能如何debug gulp

1.安装 node-inspector

 npm install -g node-inspector

2.使用node debug

node-debug $(which gulp) myTask

3.根据提示信息 访问 chrome 就行

另外你如果需要暂停你的gulp程序,需要在 gulpfile.js中加入 debugger;

gulp.task('myTask', function() {
  debugger;
  gulp
    .src('myPath/files/**/*')
    .pipe(someAction())
    .pipe(gulp.dest('newPath/files'));
});

另一种方法,使用 iron-node

http://s-a.github.io/iron-node/
https://github.com/s-a/iron-node/blob/master/docs/DEBUG-NODEJS-COMMANDLINE-APPS.md

【热门文章】
【热门文章】