Giter Site home page Giter Site logo

gulp-merge's Introduction

gulp-merge

Merge multiple streams into one stream in sequence or parallel.

NPM version Build Status

It is a wrap of merge2

Install

Install with npm

npm install gulp-merge

Usage

var gulp = require('gulp'),
  merge = require('gulp-merge'),
  concat = require('gulp-concat'),
  minifyHtml = require('gulp-minify-html'),
  ngtemplate = require('gulp-ngtemplate');

gulp.task('app-js', function () {
  return merge(
      gulp.src('static/src/tpl/*.html')
        .pipe(minifyHtml({empty: true}))
        .pipe(ngtemplate({
          module: 'genTemplates',
          standalone: true
        })
      ), gulp.src([
        'static/src/js/app.js',
        'static/src/js/locale_zh-cn.js',
        'static/src/js/router.js',
        'static/src/js/tools.js',
        'static/src/js/services.js',
        'static/src/js/filters.js',
        'static/src/js/directives.js',
        'static/src/js/controllers.js'
      ])
    )
    .pipe(concat('app.js'))
    .pipe(gulp.dest('static/dist/js/'));
});
var stream = merge([stream1, stream2], stream3, {end: false})
//...
stream.add(stream4, stream5);
//..
stream.end();
// equal to merge([stream1, stream2], stream3)
var stream = merge();
stream.add([stream1, stream2]);
stream.add(stream3);
// merge order:
//   1. merge `stream1`;
//   2. merge `stream2` and `stream3` in parallel after `stream1` merged;
//   3. merge 'stream4' after `stream2` and `stream3` merged;
var stream = merge(stream1, [stream2, stream3], stream4);

// merge order:
//   1. merge `stream5` and `stream6` in parallel after `stream4` merged;
//   2. merge 'stream7' after `stream5` and `stream6` merged;
stream.add([stream5, stream6], stream7);
// nest merge
// equal to merge2(stream1, stream2, stream6, stream3, [stream4, stream5]);
var streamA = merge(stream1, stream2);
var streamB = merge(stream3, [stream4, stream5]);
var stream = merge(streamA, streamB);
streamA.add(stream6);

API

var merge = require('gulp-merge');

merge()

merge(options)

merge(stream1, stream2, ..., streamN)

merge(stream1, stream2, ..., streamN, options)

merge(stream1, [stream2, stream3, ...], streamN, options)

return a duplex stream (mergedStream). streams in array will be merged in parallel.

mergedStream.add(stream)

mergedStream.add(stream1, [stream2, stream3, ...], ...)

return the mergedStream.

mergedStream.on('queueDrain', function() {})

It will emit 'queueDrain' when all streams merged. If you set end === false in options, this event give you a notice that should add more streams to merge or end the mergedStream.

stream

option

Type: Readable or Duplex or Transform stream.

options

option

Type: Object.

  • end - Boolean - if end === false then mergedStream will not be auto ended, you should end by yourself. Default: undefined

  • objectMode - Boolean . Default: true

objectMode and other options(highWaterMark, defaultEncoding ...) is same as Node.js Stream.

License

MIT © Teambition

gulp-merge's People

Contributors

varya avatar zensh avatar

Watchers

 avatar  avatar

Forkers

iamstarkov

gulp-merge's Issues

merge([]) leads to silent crash of gulp

Here is gulpfile.js to reproduce this bug:

var gulp = require('gulp');
var merge = require('gulp-merge');
// With `merge2` this example works as expected
//var merge = require('merge2');

gulp.task('init', function() {
  var parallelOneTimeTasks = [];

  // if (task 1 not yet done) {
  //   parallelOneTimeTasks.push(...)
  // }
  // if (task 2 not yet done) {
  //   parallelOneTimeTasks.push(...)
  // }
  // ...

  return merge(parallelOneTimeTasks);
});

gulp.task('default', ['init'], function() {
  console.log('Done!');
});

Observed output:

$ gulp
[19:32:54] Using gulpfile ~/stuff/web/gulp-merge/gulpfile.js
[19:32:54] Starting 'init'...
$

I can't reproduce this bug using merge2 installed directly --- looks like gulp-merge has outdated version of merge2.

Output with merge2:

$ gulp
[19:33:03] Using gulpfile ~/stuff/web/gulp-merge/gulpfile.js
[19:33:03] Starting 'init'...
[19:33:03] Finished 'init' after 1.33 ms
[19:33:03] Starting 'default'...
Done!
[19:33:03] Finished 'default' after 26 μs
$

BTW, it's really hard to find this source repository from gulp-merge page on NPM. Maybe you change website in package description on NPM?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.