Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
176
rated 0 times [  177] [ 1]  / answers: 1 / hits: 44171  / 11 Years ago, sat, february 22, 2014, 12:00:00
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.
);


Piping to multiple destinations when file.contents is a stream is not currently supported. What is a workaround for this problem?


More From » node.js

 Answers
46

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);
});


EDIT: This bug is now fixed in gulp. The code in your original post should work fine.


[#72376] Friday, February 21, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaidyn

Total Points: 633
Total Questions: 102
Total Answers: 100

Location: Trinidad and Tobago
Member since Thu, Dec 1, 2022
2 Years ago
;