Every time I start a node module, or a new JS project, I'm confronted with this same question: how do I structure it to allow it to be used in the browser or nodejs, without requiring a build step, and without getting in the way of my development?
While developing, I typically create some type of browser-based environment; Firebug and Web Inspector are still miles ahead of anything else we've got. Ideally I want to be able to add a file via a script
tag, and have that be the only requirement.
As @visionmedia points out, this is ridiculous.
This gist is meant to compile all of the various ways I've seen of guarding against/for a variety of module systems. Fork it and add your own, I'll try to bring them into this one.
@kirbysayshi not every files needs this though, only the file containing the chunk you want to expose. The rest could be AMD modules that are loaded in dev and then compiled/optimized for build.