本文介紹了如何使用 Gulp.js 將流保存到多個(gè)目的地?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
限時(shí)送ChatGPT賬號(hào)..
const gulp = require('gulp');
const $ = require('gulp-load-plugins')();
const source = require('vinyl-source-stream');
const browserify = require('browserify');
gulp.task('build', () =>
browserify('./src/app.js').bundle()
.pipe(source('app.js'))
.pipe(gulp.dest('./build')) // OK. app.js is saved.
.pipe($.rename('app.min.js'))
.pipe($.streamify($.uglify())
.pipe(gulp.dest('./build')) // Fail. app.min.js is not saved.
);
當(dāng)前不支持當(dāng) file.contents 為流時(shí)通過管道傳輸?shù)蕉鄠€(gè)目標(biāo).有什么辦法可以解決這個(gè)問題?
Piping to multiple destinations when file.contents is a stream is not currently supported. What is a workaround for this problem?
推薦答案
目前在使用 file.contents 作為流時(shí),每個(gè) dest 必須使用兩個(gè)流.這可能會(huì)在未來得到解決.
Currently you have to use two streams for each dest when using file.contents as a stream. This will probably be fixed in the future.
var gulp = require('gulp');
var rename = require('gulp-rename');
var streamify = require('gulp-streamify');
var uglify = require('gulp-uglify');
var source = require('vinyl-source-stream');
var browserify = require('browserify');
var es = require('event-stream');
gulp.task('scripts', function () {
var normal = browserify('./src/index.js').bundle()
.pipe(source('bundle.js'))
.pipe(gulp.dest('./dist'));
var min = browserify('./src/index.js').bundle()
.pipe(rename('bundle.min.js'))
.pipe(streamify(uglify())
.pipe(gulp.dest('./dist'));
return es.concat(normal, min);
});
此錯(cuò)誤現(xiàn)已在 gulp 中修復(fù).您原始帖子中的代碼應(yīng)該可以正常工作.
This bug is now fixed in gulp. The code in your original post should work fine.
這篇關(guān)于如何使用 Gulp.js 將流保存到多個(gè)目的地?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!