如何得到一些错误的文件丢失?

我有gulpfile.js这样设置:

var scripts = [ 'bower_components/timezone-js/src/date.js', 'bower_components/jquery/jquery.min.js', 'bower_components/jquery-migrate/jquery-migrate.js', 'bower_components/jquery-ui/ui/minified/jquery-ui.min.js', 'bower_components/jqueryui-touch-punch/jquery.ui.touch-punch.min.js', ... ]; gulp.task('scripts', function () { return gulp.src(scripts, {base: '.'}) .pipe(plumber(plumberOptions)) .pipe(sourcemaps.init({ loadMaps: false, debug: debug, })) ... 

即我所有的脚本文件都是完全匹配的。 没有发生。

每隔一段时间我就搞砸一个文件path,或者作者改变目录结构。 我希望在发生这种情况时得到通知,而不是静默地排除脚本,并导致运行时错误。

有什么办法让我做gulp.src报告这类错误?

根据这个答案使用gulp-expect-file 。

 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()); }); 

(谢谢)

gulp.src实际上只是vinyl-fs.src的别名,如下所示:

 function src(glob, opt) { opt = opt || {}; var pass = through.obj(); if (!isValidGlob(glob)) { throw new Error('Invalid glob argument: ' + glob); } // return dead stream if empty array if (Array.isArray(glob) && glob.length === 0) { process.nextTick(pass.end.bind(pass)); return pass; } var options = defaults(opt, { read: true, buffer: true }); var globStream = gs.create(glob, options); // when people write to use just pass it through var outputStream = globStream .pipe(through.obj(createFile)) .pipe(getStats(options)); if (options.read !== false) { outputStream = outputStream .pipe(getContents(options)); } return outputStream.pipe(pass); } 

它反过来使用使用glob的glob-stream 。 你可能会绕过大部分,直接使用通过2来创build一个pipe道从数组文件。 我还没有想出如何做到这一点呢。