本文介绍了如何从乙烯基物体中获得口香糖流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用乙烯基对象创建流,所以我可以在上面使用gulp.js插件吗?

How can I create a stream using a vinyl object so I can use gulp.js plugins on it?

带有乙烯基对象的示例:

Example with a vinyl object:

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())... )解决了第一种情况.

lofihelsinki's comment (return file.pipe(css())...) solves this first case.

带有乙烯基对象和流的示例:

Example with a vinyl object and a stream:

var file = getFoo();
return merge(gulp.src('*.css'), file)
    .pipe(concat('foobar.css'))
    .pipe(css(opts))
    .pipe(gulp.dest('...'));

带有两个乙烯基对象的示例:

Example with two vinyl objects:

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/包/gulp-streamify )并添加新的 pipe 以转换为流.您可以使用 gulp-map 明确地执行此操作,例如

You can use vinyl-source-stream or equivalent (https://www.npmjs.com/package/gulp-streamify)and add new pipe to convert to the stream.You can explicitly do that with gulp-map like here

这篇关于如何从乙烯基物体中获得口香糖流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 11:41