Weepy,

Thanks for working on this & for open-sourcing it!

When I first started working with node, I searched for this kind of thing & 
landed on brequire as a way to reduce boilerplate on files that I wanted to 
use in the browser as well as from node. It worked well for me and eased my 
transition to working with node. After that I tried browserify and after 
that I went back to writing the boilerplate on every file (by boilerplate, 
I mean lines like "var _ = root._ || require('underscore');" at the top of 
the file and "if (typeof require == 'undefined') // assign to a global else 
use exports" at the bottom) -- the kind of boilerplate that you find in 
libraries designed to work in both environments, like backbone, underscore 
and async.

The three methods have their pros and cons. Browserify shines when you need 
to make node libraries (that you have no control over) work in the browser 
(things like Request, EventEmitter, util.inherits, etc -- they all "just 
work"). But the way that it puts all the JS into a single file makes 
debugging cumbersome if you're debugging more than just one of the files 
(the main file isn't so bad b/c the line numbers match, but if you end up 
debugging any of the dependencies, it gets awkward).

Brequire is nicer for debugging because it doesn't bundle everything into a 
single file, but it doesn't do all the magic that browserify does on 
3rd-party files, so it's best for when you're authoring the JS yourself and 
not using a lot of node-specific dependencies. It is especially helpful if 
you're writing lots of small files in the same module (since this would 
otherwise mean a lot of boilerplate and since it's just one large module, 
it's not a big deal to require Brequire).

Just including the boilerplate in each file is (IMO) a better approach when 
you're splitting your work into lots of small-and-sharp single-purpose 
modules and trying to encourage their use independent of the larger project 
(fewer dependencies = easier/higher adoption). I also tend to use fewer, 
larger files (one file per namespace instead of one file per class), like 
Backbone, Underscore and the core node modules, which reduces the pain of 
the boilerplate.

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to