ForbesLindesay/browserify-middleware — pull request #33 by bjoerge (2014-01-10 23:50:39+00:00)
Title: Precompile option

Here's a suggested fix for #31 / #32

Introduced a `precompile` setting that can be set according to the version (directory, file or modules):

This is how to use it:

```javascript
// Precompile a single file in a directory
app.use('/js', browserify('./client/dir', {
cache: true,
precompile: 'beep.js'
}));

// Precompile multiple files in a directory
app.use('/js', browserify('./client/dir', {
cache: true,
precompile: ["beep.js", "subdir/boop.js"]
}));

// Precompile a browserified file at a path
app.get('/js/file.js', browserify('./client/file.js', {
cache: true,
precompile: true
}));

// Precompile a bundle exposing `require` for a few npm packages.
app.get('/js/bundle.js', browserify(['hyperquest', 'concat-stream'], {
cache: true,
precompile: true
}));
```

A few things to consider:
- Precompiling is disabled in all environments by default
- For the directory version you must opt-in on the bundles you want precompiled, as precompiling *all* files in a directory will potentially be overly expensive (as noted by @ForbesLindesay in #31). I have a feeling that opting in will cover the most common use cases anyways.
- It only makes sense to precompile if caching is enabled. The `precompile` option is ignored if `!settings.cache`

Any suggestions/improvements are welcome :-)