ForbesLindesay / browserify-middleware

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

precompile does not seem to work #78

Closed benoitguigal closed 9 years ago

benoitguigal commented 9 years ago

I am using browserify-middleware in production with NODE_ENV='production'. According to the documentation, precompileshould be set to true. However, my first request after server start up takes a lot of time (~30s to serve /bundles/shared.js). Here is my code :

var browserify = require('browserify-middleware');
var reactify = require('reactify');
browserify.settings('transform', ['reactify']);

var shared = ['react', 'superagent'];
router.get('/bundles/shared.js', browserify(shared));

does it have something to do with requiring external libraries ?

filod commented 9 years ago

+1 for this

JedWatson commented 9 years ago

React takes a lot of time to compile (although I'm seeing avg. 6 seconds on a newish macbook air, not 30)

browserify-middleware will wait until the bundle is built before serving it, whether its built on demand or precompiled (i.e. if you precompile but then immediately request the bundle, you'll experience the same wait)

Are you sure this isn't working as expected? To verify:

arnemart commented 9 years ago

I am experiencing the same issue – the bundle is definitely not being precompiled, even when setting { cache: true, precompile: true } explicitly.

app.get('/bundle.js', browserify('./browser.js', { cache: true, precompile: true }));

As far as I can scry from reading the source, caching the output happens in the send.js file, but the precompile option calls the compile module which does not touch this cache. I may be entirely missing how this works though :-)

If you point me in the right direction I'd be happy to provide a PR if I find a fix.

ralucas commented 9 years ago

+1 as I've noticed this issue on Heroku which has 30s request timeout. Is there a workaround?

ForbesLindesay commented 9 years ago

This should now be fixed in latest, in fact precompile is completely un-necessary now because we pre-compile everything (except folders).