Monday, March 8th, 2010
modulr: a CommonJS module implementation in Ruby for client-side JavaScript
<>blockquote>modulr is a CommonJS module implementation in Ruby for client-side JavaScript
Ruby? what does that have anything to do with it? Ah, its from one of those Prototype guys isn't it.... Yup, Tobie is at it again, this time with modulr:
modulr accepts a singular file as input (the program) on which is does static analysis to recursively resolve its dependencies.
The program, its dependencies and a small, namespaced JavaScript library are concatenated into a single js file.
The bundled JavaScript library provides each module with the necessary require function and exports and module free variables.
This can also help sharing that CommonJS code. I recently did just that and had some:
-
-
// check to see if you are running inside of node.js and export if you are
-
if (typeof GLOBAL == "object" && typeof GLOBAL['node'] == "object") {
-
exports.Appetite = Appetite;
-
}
-
Related Content:











Just released modulr as a ruby gem. Updated the README accordingly.
To process a JavaScript source file, just run:
$ modulrize filename.js > output.jsMaybe it’s just me but i don’t understand what this does or what it’s good for.
Sometimes articles on Ajaxian raise more questions than they answer.
@Jaap: The project readme on the Github says the following:
“The program, its dependencies and a small, namespaced JavaScript library are concatenated into a single js file. This improves load times by minimizing HTTP requests.”
So, it looks like a dependency resolver/JS concatenator?
Yes, that’s correct.
It’s based on the CommonJS module 1.0/1.1 specs which it implements.
I can see the server side. Does it have client side as well? How is it different from sprockets?
icoloma, modulr is relatively similar to Sprockets. Unlike Sprockets, modulr implements CommonJS modules, so code written for modulr is compatible with other CommonJS implementations. Sprockets handles assets (CSS files, images, etc.) which modulr doesn’t do.
This sounds just like sprockets. I guess I will have to dig in to see.