npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-overlay

v0.0.2

Published

Merge two gulp streams by overlaying one onto the other

Downloads

67

Readme

npm Version Build Status Coverage Status Dependency Status devDependency Status Code Climate Codacy Badge

gulp-overlay

Merge two gulp streams by overlaying one onto the other.

Installation

npm install --save-dev gulp-overlay

Usage

Assume the following folder structure:

src/
  common/
    menu.html
    main.html
    footer.html
    pages/
      about.html
  project1/
    menu.html
    main.html
    pages/
      about.html
      tos.html
  project2/
    main.html
    footer.html
    pages/
      legal.html

You can use overlay.with() to overlay project1/ on top of common/. Files in project1/ will overwrite the corresponding files in common/.

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

gulp.task('build-project1', function() {
  return gulp.src('src/common/**/*.html')
    .pipe(overlay.with(gulp.src('src/project1/**/*.html')))
    .pipe(gulp.dest('dist/project1'));
});

gulp.task('build-project2', function() {
  return gulp.src('src/common/**/*.html')
    .pipe(overlay.with(gulp.src('src/project2/**/*.html')))
    .pipe(gulp.dest('dist/project2'));
});

Alternatively you can use overlay.onto() to do the same thing:

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

gulp.task('build-project1', function() {
  return gulp.src('src/project1/**/*.html')
    .pipe(overlay.onto(gulp.src('src/common/**/*.html')))
    .pipe(gulp.dest('dist/project1'));
});

gulp.task('build-project2', function() {
  return gulp.src('src/project2/**/*.html')
    .pipe(overlay.onto(gulp.src('src/common/**/*.html')))
    .pipe(gulp.dest('dist/project2'));
});

The result in both cases is the following:

dist/
  project1/
    menu.html     1
    main.html     1
    footer.html   *
    pages/
      about.html  1
      tos.html    1
  project2/
    menu.html     *
    main.html     2
    footer.html   2
    pages/
      about.html  *
      legal.html  2

*: files from the src/common/ directory
1: files from the src/project1/ directory
2: files from the src/project2/ directory

Minimizing memory utilization

gulp-overlay doesn't need file contents to do its job. It is therefore recommended that you defer reading file contents by providing the read:false option to gulp.src(). You can read the file contents later by placing gulp-read somewhere after gulp-overlay in your stream:

var overlay = require('gulp-overlay');
var read = require('gulp-read');
  
gulp.task('build-project1', function() {
  return gulp.src('src/project1/**/*.html', {read:false})
    .pipe(overlay.onto(gulp.src('src/common/**/*.html', {read:false})))
    .pipe(read())
    .pipe(gulp.dest('dist/project1'));
});

Since all files of the second stream have to be stored in memory for gulp-overlay to work, this potentially saves a lot of memory when dealing with a large number of files.

This also has the added benefit that not all the file contents have to be read, since some files will be replaced by others anyway.

Enforcing file order

gulp-overlay can only keep the ordering of the first stream. Any remaining files from the second stream will be emitted afterwards and in no particular order. If the order of files is important in your stream, you should place gulp-order or gulp-sort somewhere after gulp-overlay:

var overlay = require('gulp-overlay');
var order = require('gulp-order');

gulp.task('build-project1', function() {
  return gulp.src('src/project1/**/*.js')
    .pipe(overlay.onto(gulp.src('src/common/**/*.js')))
    .pipe(order(['vendor/**/*.js', 'app/**/*.js']))
    .pipe(gulp.dest('dist/project1'));
});

License

MIT