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-watchify-factor-bundle

v2.0.0

Published

Use watchify and factor-bundle in gulp

Downloads

577

Readme

gulp-watchify-factor-bundle

version status coverage dependencies devDependencies

A sugar wrapper for browserify, watchify and factor-bundle to work with gulp.

The main ideas are borrowed from reduce-js.

Usage

gulpfile.js:

var reduce = require('gulp-watchify-factor-bundle')
var gulp = require('gulp')
var path = require('path')
var buffer = require('vinyl-buffer')
var uglify = require('gulp-uglify')
var del = require('del')

gulp.task('clean', function () {
  return del('build')
})

gulp.task('build', ['clean'], function () {
  var basedir = path.join(__dirname, 'src')

  // Create a browserify instance
  // same with `browserify(opts)`
  var b = reduce.create({ basedir: basedir })

  // find entries
  // same with gulp.src()
  return reduce.src('page/**/index.js', { cwd: basedir })
    // apply `factor-bundle`
    // and call b.bundle() which produces a vinyl stream now
    .pipe(reduce.bundle(b, { common: 'common.js' }))

    // apply gulp plugins to process the vinyl stream
    .pipe(buffer())
    .pipe(uglify())

    // same with gulp.dest
    .pipe(reduce.dest('build'))
})

gulp.task('watch', ['clean'], function () {
  var basedir = path.join(__dirname, 'src')

  // Create a browserify instance
  // same with `browserify(opts)`
  var b = reduce.create({ basedir: basedir })

  b.on('log', console.log.bind(console))

  // find entries
  // same with gulp.src()
  return reduce.src('page/**/index.js', { cwd: basedir })
    // apply `factor-bundle` and `watchify`
    .pipe(reduce.watch(b, { common: 'common.js' }))
    // whenever `b.bundle()` is called,
    // event 'bundle' is fired
    .on('bundle', function (vinylStream) {
      // vinylStream = b.bundle()
      vinylStream
        // apply gulp plugins to process the vinyl stream
        .pipe(buffer())
        .pipe(uglify())
        // same with gulp.dest
        .pipe(reduce.dest('build'))
    })
})

Exports

create()

Same with the browserify constructor.

bundle(b, bundleOptions)

A gulp plugin to use browserify with factor-bundle, and produces a vinyl stream.

b

The browserify instance.

bundleOptions

Options for factor-bundle.

bundleOptions.common specifies the path to the common bundle. All other options are exactly the same with those consumed by factor-bundle.

NOTE

bundleOptions.outputs must be an array of file paths. However, if not specified, a new bundle is created for each entry, with the same path with the entry.

watch(b, bundleOptions, watchifyOptions)

A gulp plugin to use browserify with factor-bundle and watchify.

b

The browserify instance.

bundleOptions

Options for factor-bundle.

watchOptions

Options for watchify.

NOTE This method creates a transform to process the entry stream, and emit a bundle event whenever b.bundle() called.

reduce.watch().on('bundle', vinylStream => {})