ForbesLindesay / browserify-middleware

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

Add example of usage with browserify-shim #38

Closed knownasilya closed 10 years ago

knownasilya commented 10 years ago

I'm not sure how to go about merging the two, would be helpful to have an example using browserify-shim.

ForbesLindesay commented 10 years ago

Just follow the instructions in their readme. You should only need it when adapting legacy modules. What module are you trying to use?

knownasilya commented 10 years ago

I'm shimming modules coming from bower which aren't CommonJS compliant. Should I be setting up the transform in the `package.json' or in the module that sets up express?

Is there a way to use this middleware with watchify?

ForbesLindesay commented 10 years ago

This middleware negates the need for watchify. They are two ways of achieving the same goal. Watchify automatically updates files on disk, so that when you refresh you should get the latest version. This just re-compiles whenever you refresh the browser. Both modules cache files that have not changed intelligently.

I would recommend looking for npm versions of anything in bower, most things will already exist somewhere. If not, ideally it would be great to release a CommonJS version.

If you want to use bower modules that don't support browserify as they stand, you should use browserify-shim. Just add the browserify-shim settings to the package.json in the root folder of your application. That should work. Alternatively you can probably put individual package.json files in each bower package's folder. Do whichever seems easier.

You may have better luck asking in the browserify-shim package, since there shouldn't be anything special about browserify-middleware when it comes to using the two together.

robmunro commented 10 years ago

I too was wondering if there was anyway of getting watchify working with browserify-middleware. Does browserify-middleware cache each of the imports separately (and the file importing these) and only rebuild parts that change and re-bundling the parts?

I'd argue that there is a significant advantage to having rebuilding the way watchify works as opposed to on request of that file. Browserify can be kinda slow, so anything that helps to build the required bundles faster is a win IMHO. Even 2 seconds saving for a developer on the "edit, save, wait for rebuild" cycle can lead to seriously significant time savings across a dev team. Also at the end of this cycle, if using livereload, we can have the page reload which saves even more time. Even more than the time saved, I find it's extremely helpful for maintaining focus - as I don't attempt to "not waste time" and do something else while I am waiting. Us developer types get distracted easily:)