> you could create one: > <!-- script which defines `require`, `module.exports` -->
This is essentially what brequire is (client-side CommonJS) -- https://github.com/weepy/brequire. This works and is nicer than the typical browserify usage because it doesn't bundle all dependencies into a large, single standalone file. Note that browserify now supports this use-case as well. While this brings some advantages (a module system, dependency management, etc), it often isn't what client-side developers want. The majority of client-side developers are not node developers. Even if you make all your node-module-handling stuff transparent to client-side users of your code, there is still a price-tag in weight and in complexity for client-side developers who want to read and understand the code that they're bringing into their project. If your modules have a ton of fine-grained dependencies or multiple layers of dependencies or a lot of node-specific dependencies, then using brequire or browserify or something similar can make your life easier. But if not - and especially if your goal is maximum adoption of your modules by client-side developers - you may want to consider following the lead of Underscore and Backbone and add a few lines of boilerplate to each file so client-side developers can use your code according to client-side idioms. -- peter From: [email protected] [mailto:[email protected]] On Behalf Of aeosynth Sent: Monday, July 22, 2013 6:12 AM To: [email protected] Subject: [nodejs] Re: How to write a JavaScript library for client or server use i'm not aware of anything that works without a build step or an async loader, but conceivably you could create one: <!-- script which defines `require`, `module.exports` --> <script src="definitions.js"></script> <!-- your class files --> <script src="Foo.js"></script> <script src="Bar.js"></script> ... <!-- your app's code --> <script src="app.js"></script> note that for this to work, your class files must not run any top level code which depends on another module -- -- 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 a topic in the Google Groups "nodejs" group. To unsubscribe from this topic, visit https://groups.google.com/d/topic/nodejs/I9NoW70iQTo/unsubscribe. To unsubscribe from this group and all its topics, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out. -- -- 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.
