Gulp.js通过not test / prod处理开发

时间:2015-01-01 18:02:05

标签: node.js phantomjs gulp

我有一个gulp.js进程使用gulp-phantom插件,它完全适用于我的开发设置,Mac OS X 10.10,但是在我的测试/产品环境(EC2 Amazon Linux)上,它根本不起作用,但它也没有提供任何类型的错误信息或任何其他有用的输出,任务刚刚开始并几乎立即完成:

开发环境输出:

$ gulp crawlSite
[17:39:19] Using gulpfile ~/Documents/dev/mysite.co.uk/gulpfile.js
[17:39:19] Starting 'crawlSite'...
[17:40:15] Finished 'crawlSite' after 57 s

测试环境输出:

$ gulp crawlSite
[17:34:27] Using gulpfile /var/www/html/mysite.co.uk/gulpfile.js
[17:34:27] Starting 'crawlSite'...
[17:34:27] Finished 'crawlSite' after 715 ms

正如您在开发环境中看到的那样,该过程需要57秒,但是在测试时它只有715毫秒,并且在测试时它不会创建我的幻像脚本应该创建的文件。我的gulp任务非常简单:

gulp.task('crawlSite', function() {
  return gulp.src("phantom-crawl-website.js")
    .pipe(phantom());
});

和我的幻像脚本“phantom-crawl-website.js”文件与gulpfile.js文件位于同一目录中。

我已检查所有节点模块是否已安装且PhantomJS是否全局安装在测试环境中,所有内容都检查正常。如果我跑:

$ phantomjs phantom-crawl-website.js

从测试环境的命令提示符下运行正常,它会抓取站点并创建文件。

我曾尝试使用gulp-phantom选项进行“调试”但是我似乎永远不会看到任何输出。我尝试过使用gulp-debug以及如下:

gulp.task('crawlSite', function() {
  return gulp.src("phantom-crawl-website.js")
    .pipe(phantom({debug: true}))
    .pipe(debug());
});

但是这一切都是给我一个gulp-phantom输出文件名(“phantom-crawl-website.txt”)。我也尝试用以下方式编写gulp-phantom输出文件:

gulp.task('crawlSite', function() {
  return gulp.src("phantom-crawl-website.js")
    .pipe(phantom({debug:true}))
    .pipe(gulp.dest("./phantomOutput/"));
});

但我得到的是在“phantomOutput”目录中创建的名为“phantom-crawl-website.txt”的空白文件。

任何人都可以告诉我我做错了什么以及如何能够看到phantomJS调试输出,这样我就可以解决问题所在。

非常感谢。

更新

我通过在gulp-phantom index.js文件中添加以下内容,设法从gulp-phantom进程获得一些输出:

program.stderr.on('data', function (data) {
  console.log('stderr: ' + data);
});

添加完成后,我现在收到以下错误消息:

stderr: Can't open '/dev/stdin'

但实际上还没有运气让它发挥作用。

1 个答案:

答案 0 :(得分:0)

发现了这个问题。在gulp-phantom模块中,似乎有一个错误,使用/ dev / stdin是phantomjs期望幻像文件名被传递。在Mac OS X上,/ dev / stdin包含文件的内容,但在Linux上,它被拒绝读取它的权限。

为了解决这个问题,我删除了推送' / dev / stdin'进入参数堆栈,然后在"通过"中进一步向下添加一个函数调用将完整路径和文件名传递给phantomjs进程。

我将向gulp-phantom模块创建者发出拉取请求,看看他们是否接受此作为问题的修复。