How to save a stream into multiple destinations with Gulp.js?(如何使用 Gulp.js 将流保存到多个目的地?)
问题描述
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.
);
当前不支持当 file.contents 为流时通过管道传输到多个目标.有什么办法可以解决这个问题?
Piping to multiple destinations when file.contents is a stream is not currently supported. What is a workaround for this problem?
推荐答案
目前在使用 file.contents 作为流时,每个 dest 必须使用两个流.这可能会在未来得到解决.
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);
});
此错误现已在 gulp 中修复.您原始帖子中的代码应该可以正常工作.
This bug is now fixed in gulp. The code in your original post should work fine.
这篇关于如何使用 Gulp.js 将流保存到多个目的地?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 Gulp.js 将流保存到多个目的地?


基础教程推荐
- 在for循环中使用setTimeout 2022-01-01
- 有没有办法使用OpenLayers更改OpenStreetMap中某些要素 2022-09-06
- 响应更改 div 大小保持纵横比 2022-01-01
- 动态更新多个选择框 2022-01-01
- 我什么时候应该在导入时使用方括号 2022-01-01
- 当用户滚动离开时如何暂停 youtube 嵌入 2022-01-01
- 在 JS 中获取客户端时区(不是 GMT 偏移量) 2022-01-01
- 角度Apollo设置WatchQuery结果为可用变量 2022-01-01
- Karma-Jasmine:如何正确监视 Modal? 2022-01-01
- 悬停时滑动输入并停留几秒钟 2022-01-01