ForbesLindesay / browserify-middleware

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

Passing options to transforms #52

Closed refractalize closed 9 years ago

refractalize commented 10 years ago

Some transforms allow options to be passed to them, and this is supported in browserify command line and API, and now in browserify-middlware.

See readme for docs.

transform: [["transform", {option1: true, ...}], "other-transform"]
ForbesLindesay commented 10 years ago

You can already do this fairly easily by just having:

var transform = require('transform');
options.transform = [[function (file) {
  return transform(file, {option1: true, ...});
}], "other-transform"]

It might be worth considering dedicated support though, I'm not sure.

refractalize commented 10 years ago

Good point, I didn't know you could do that so easily. But maybe that's the point, perhaps dedicated and documented support would be more obvious?

refractalize commented 10 years ago

Any further comment on this? I understand you can do it as above, but having explicit (and documented) support would make it easier for others - as does the browserify API itself. What do you think?

suy commented 10 years ago

Hi. FWIW, I've successfully managed to do this to pass options to a transform:

var browserify = require('browserify-middleware');
browserify.settings({
    transform: [function(file) {
        return require('jstify')(file, { engine: 'lodash' });
    }]
});
app.use('/app.js', browserify('./client/app.js'));

If you don't think the change to the code is necessary, I can try to submit a hint in the docs, since I think is non-obvious as of right now.

Thank you for the project. Is been quite helpful.

suy commented 9 years ago

Thank you!