ForbesLindesay / browserify-middleware

express middleware for browserify, done right
http://browserify.org
MIT License
381 stars 66 forks source link

Feaute request: callbacks in postcompile/preminify/postminify hooks #92

Closed HowlingEverett closed 6 years ago

HowlingEverett commented 8 years ago

Use case: Source map support is great, but it would be awesome to be able to get that source map into an external file rather than concatenated inline. The existing tool for that is exorcist, but it's a streaming interface.

It's fairly easy to hook exorcist to take a string, write out the sourcemap, and then consume the modified source string, but not synchronously.

Without modifying the behaviour of the middleware itself, I feel like the most flexible way would be to modify the hooks to take an optional callback. If a callback is passed, hook into it rather than assuming the hooks will act as synchronous processing functions.

Trivial example:

browserify('../public/bundle.js', {
    postminify: function(source, done) {
        process.nextTick(function() {
             // Do something async
             done();
        })
    }
});
HowlingEverett commented 8 years ago

Interesting to note - this already works as is if you supply a promise as the function, since you're returning the result of the hook inside a then callback.

Maybe the result of this feature request is just to update the documentation to make it explicit that you can pass a Promise to the hook.