如果内容包含字符串,则从Gulp流中排除文件



我有一个吞咽任务,看起来像这样:

return src(['storage/framework/views/*.php'])
.pipe(htmlmin({
collapseWhitespace: true,
}))
.pipe(dest('storage/framework/views'));

它从Laravel获取编译后的视图,并通过htmlmin进行管道传输。

这对HTML视图很好,但会破坏Markdown视图的内容。

不幸的是,我无法在src([...])中添加排除项,因为文件名都是散列。如果文件包含mail::message,我需要能够检查文件的内容并排除该文件。

试图自己解决这个问题,有一个gullow-controls,但似乎只有当文件包含给定的字符串时才能抛出错误。我想不出用它的回调来排除文件的方法。

还有gullow-ignore,但这似乎无法将单个文件排除在流之外。

假设有三个模板文件,其中y.php是Markdown模板。理想的解决方案是:

return src(['storage/framework/views/*.php']) // [x.php, y.php, z.php]
.pipe(exclude_files_containing('mail::message')) // [x.php, z.php]
.pipe(htmlmin({
collapseWhitespace: true,
}))
.pipe(dest('storage/framework/views'));

使用gulp-filter

const filter = require('gulp-filter');
gulp.task("TaskExample", function () {
// return true if want the file in the stream
// return file to exclude the file
const excludeMessageFilter = filter(function (file) {
let contents = file.contents.toString();
return !contents.match('mail::message');
});
return gulp.src('storage/framework/views/*.php')
.pipe(excludeMessageFilter)
// .pipe(htmlmin(...
// .pipe(gulp.dest('''''''));
});

最新更新