[英]Handling Gulp.js vinyl stream errors properly when errors are thrown from streaming libs
[英]How to get a gulp stream from a vinyl object?
如何使用乙烯基對象創建流以便我可以在其上使用 gulp.js 插件?
乙烯基物體的示例:
var file = getFoo(); // An in-memory file as a vinyl object.
return gulp.src(file) // What to do here? gulp.src only accepts globs.
.pipe(css(opts)) // (gulp-clean-css)
.pipe(gulp.dest('...'));
lofihelsinki 的評論( return file.pipe(css())...
)解決了第一種情況。
帶有乙烯基對象和流的示例:
var file = getFoo();
return merge(gulp.src('*.css'), file)
.pipe(concat('foobar.css'))
.pipe(css(opts))
.pipe(gulp.dest('...'));
兩個乙烯基物體的示例:
var file1 = getFoo();
var file2 = getBar();
return merge(file1, file2) // (gulp-merge)
.pipe(concat('foobar.css')) // (gulp-concat)
.pipe(css(opts))
.pipe(gulp.dest('...'));
您可以使用vinyl-source-stream或等效項( https://www.npmjs.com/package/gulp-streamify )並添加新pipe
以轉換為流。 你可以像這里一樣使用gulp-map明確地做到這一點
文件本身是一個可用的對象
var file = getFoo();
return file
.pipe(css(opts))
.pipe(gulp.dest('...'));
對於兩個流,使用gulp-buffer
var buffer = require('gulp-buffer');
var file1 = getFoo();
var file2 = getBar();
return merge(file1, file2) // (gulp-merge)
.pipe(buffer()) // (gulp-buffer)
.pipe(concat('foobar.css')) // (gulp-concat)
.pipe(css(opts))
.pipe(gulp.dest('...'));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.