watchify2

0.1.0 • Public • Published

watchify2

version status

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.

Package Sidebar

Install

npm i watchify2

Weekly Downloads

8

Version

0.1.0

License

MIT

Last publish

Collaborators

  • zoubin