gulp silently failing - no errors printed to console

纵然是瞬间 提交于 2019-12-04 23:35:44
Adam Grant

Okay, so Gulp is working "correctly." But what I'm hearing in your question is that it would be nice if Gulp could just tell you if a file doesn't exist.

I use gulp-expect-file as such

var coffee = require('gulp-coffee');
var expect = require('gulp-expect-file');

gulp.task('mytask', function() {
  var files = ['idontexist.html'];

  return gulp.src(files)
    .pipe(expect(files))
    .pipe(coffee());
});

Now you'll see this in the terminal:

robrich

If the path does not exist, gulp.src successfully pushes exactly nothing through the pipe, the sass and dest tasks successfully are never called, and with that, gulp.src's stream ends, signaling the default task is complete, and gulp exits. It has done exactly what you've told it to. :D

danactive

I agree with @adamjgrant use gulp-expect-file.

var expect = require('gulp-expect-file'),
    gulp = require('gulp');

gulp.task('task', function() {
    var files = ['src/js/*.js'];
    gulp
        .src(files)
        .pipe(expect(files));
});

PS: Grunt.js handles this with nonull:true

lint: {
    src: ['gruntfile.js', 'gulpfile.js'],
    nonull: true
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!