jmreidy/grunt-browserify — pull request #59 by latentflip (2013-06-18 16:33:40+00:00)
Title: Implement cached rebundling, fixes #53

Okay, this should work :smile:. It probably needs a little discussion before going live though.

To use it, just update your package to point to this fork/copy it down/whatever. Out of the box you'll see no differences, but combine it with `grunt-contrib-watch` and you'll get nice fast recompiling.

If you set up your gruntfile with any old watcher, it will recompile whenever it fires, so perhaps:

```javascript
grunt.initConfig({
watch: {
coffeescripts: {
files: ['app/**/*.*']
}
}
//...
})
```

If you have multiple watchers for different things, you can tell browserify to only listen to one of those using the `watchKey` option. So you might do something like:

```javascript
grunt.initConfig({
browserify: {
app: {
dest: 'dist/bundle.js',
src: 'app/app.coffee',
options: {
transform: ['coffeeify'],
watchKey: 'watch.browserifyapp'
}
},
test: {
dest: 'dist/specs.js',
'spec/specs.coffee',
options: {
transform: ['coffeeify'],
watchKey: 'watch.browserifyspecs'
}
}
},
watch: {
browserifyapp: {
files: ['app/**/*.*']
},
browserifyspecs: {
files: ['specs/**/*.*', 'app/**/*.*']
},
someOtherWatcher: {
files: ['foo/**/*.*']
},
}
//...
})
```

This would just rebundle `app` when `watch.browserifyapp` fires, and `test` when `someOtherWatcher` fires. Once you've done this, rebuilds are pretty much instantaneous.