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.
Thanks for the examples, I added lodash!
I think what really gets to me is that every file needs something like this. And yes, I realize that a build step can fix it, but having a build step required for development is a significant time expense due to repetition.
I'm working on splitting Vash into two files, the compiler and the runtime, and was hoping for a way to avoid having a huge guard in each, but looks like it's unavoidable.