我已经像这样设置了 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,
}))
...
也就是说,我所有的脚本文件都是完全匹配的。没有通配符。
时不时地,我弄乱了文件路径,或者作者更改了目录结构。我希望在发生这种情况时收到通知,而不是默默地排除脚本并导致运行时错误。
有什么方法可以让 gulp.src
报告这些类型的错误吗?
最佳答案
使用gulp-expect-file根据 this answer .
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());
});
(感谢rve)
关于javascript - 如何在丢失文件时出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30265677/