2017-05-23 28 views
0

如何使用vinyl對象創建流,以便我可以使用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('...')); 
+0

'return file.pipe(css())'工作嗎? – lofihelsinki

+0

它的工作原理,謝謝!我還有另外一個情況,它不會幫助,但我會在一分鐘內更新這個問題。 –

+0

我會把它變成一個答案。 – lofihelsinki

回答

0

文件本身是一個可用的對象

var file = getFoo(); 
return file 
    .pipe(css(opts)) 
    .pipe(gulp.dest('...')); 
+0

謝謝。我昨天在您的評論後添加了兩個例子。雖然問題保持不變(使用乙烯基對象創建流),但調用File的管道並不涵蓋存在接受流的函數的情況。 –

+0

如果只有一個空管('file.pipe()')是將文件轉換爲流的可行方式。也許寫一個啞巴函數來傳遞文件內容像'file.pipe(asIs())'會有幫助,我會看看這個。 –

0

對於兩個流,使用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('...')); 
相關問題