watchify2 / 0.1.0 last updated a month ago created on Sep 22nd 2013

Install

npm install --save watchify2

Clone

git clone git@github.com:reducejs/watchify2.git

dependencies show all 305

main anymatch 1.3.0 ISC
browserify 13.0.0 MIT
defined 1.0.0 MIT
outpipe 1.1.1 MIT
through2 2.0.1 MIT

maintainers

zoubin

versions

0.1.0 a month ago zoubin
0.0.1 a month ago zoubin
0 Downloads yesterday.

readme

watchify2

This is a clone for watchify to support detecting new entries.

It is based on this pr, and once watchify handles watching adding/removing entry files, this package will be deprecated.

Example

Command line

cd example/files
//bin/cmd.js main.js -o bundle.js --entry-glob='main*.js'

# new entry
cp main.js main2.js

# edit `main2.js` and save to see the change

# delete entry
rm main2.js

API

var fs = require('fs')
var browserify = require('browserify')

var b = browserify({
  basedir: __dirname + '/files',
  cache: {},
  packageCache: {},
  entries: './main.js',
})

b.plugin(__dirname + '//', { entryGlob: 'main*.js' })

b.on('update', bundle)

bundle()

function bundle() {
  console.log('UPDATE')
  b.bundle().pipe(fs.createWriteStream('bundle.js'))
}

Creating multiple bundles

var vfs = require('vinyl-fs')
var del = require('del')
var browserify = require('browserify')
var through = require('through2')

var b = browserify({
  basedir: __dirname + '/files',
  cache: {},
  packageCache: {},
  entries: './main.js',
})

b.plugin(__dirname + '//', { entryGlob: 'main*.js' })
b.plugin(dedupify)
b.plugin('common-bundle', { groups: '**/main*.js' })

b.on('update', bundle)
bundle()

function bundle() {
  console.log('UPDATE')
  var build = __dirname + '/build'
  del(build)
  b.bundle().pipe(vfs.dest(build))
}

function dedupify(b) {
  var undef
  b.on('reset', hook)
  hook()

  function hook() {
    b.pipeline.get('dedupe').unshift(through.obj(function (row, enc, next) {
      if (row.entry && row.dedupe) {
        row.dedupe = undef
        row.dedupeIndex = undef
      }
      next(null, row)
    }))
  }
}

The dedupify plugin in the example above is used to fix a known problem with browserify (see substack/factor-bundle#51).

Right now it is a little tricky to detect new entries with factor-bundle, so common-bundle is used instead.

Resolving all dependencies.. This could take a while as our cache is not yet fully warmed up.