我正在尝试使用gulp-if和gulp-is-binary来跳过我的 HTML 任务中的二进制文件,但我遇到了很多麻烦。
我有这个任务:
// html task, converts includes & variables in HTML
gulp.task("html", function () {
"use strict";
// development HTML directory
var htmlDirectory = dev;
// production HTML directory (if --dist is passed)
if (argv.dist) htmlDirectory = dist;
// clean directory if --dist is passed
if (argv.dist) del([htmlDirectory + "/**/*", "!" + htmlDirectory + "{/assets,/assets/**}"]);
// process HTML
return gulp.src([src + "/**/*", "!" + src + "{/assets,/assets/**}"])
// prevent breaking on error
.pipe(plumber({errorHandler: onError}))
// check if source is newer than destination
.pipe(gulpif(!argv.dist, newer({dest: htmlDirectory, extra: [src + "{/partials,/partials/**}"]})))
// check if a file is a binary
.pipe(gulpif(isBinary(), function () { /* somehow skip? */ } ))
// replace variables
.pipe(fileinclude({
prefix: "@@",
basepath: "@file",
context: {
name: name,
description: description,
version: version,
repository: repository,
license: license,
}
}))
// replace FontAwesome placeholders
.pipe(replace(/(?:<icon:)([A-Za-z0-9\-\_]+)[^>]*(?:>)/g, "<i class='fa fa-$1' aria-hidden='true'><\/i>"))
// output to the compiled directory
.pipe(gulp.dest(htmlDirectory))
// reload the files
.pipe(browserSync.reload({stream: true}))
// notify that the task is complete, if not part of default or watch
.pipe(gulpif(gulp.seq.indexOf("html") > gulp.seq.indexOf("default"), notify({title: "Success!", message: "HTML task complete!", onLast: true})))
// push the task to the ranTasks array
.on("data", function() {
if (ranTasks.indexOf("html") < 0) ranTasks.push("html");
});
});
这是我遇到问题的行:
.pipe(gulpif(isBinary(), function () { /* somehow skip? */ } ))
我不知道如何告诉 Gulp 跳过该文件并继续其余的任务。我觉得我错过了一些简单的东西。