Monday, March 8th, 2010

modulr: a CommonJS module implementation in Ruby for client-side JavaScript

Category: JavaScript, Ruby

<>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:

javascript
< view plain text >
  1. // check to see if you are running inside of node.js and export if you are
  2. if (typeof GLOBAL == "object" && typeof GLOBAL['node'] == "object") {
  3.     exports.Appetite = Appetite;
  4. }

Posted by Dion Almaer at 6:28 am
7 Comments

++---
2.2 rating from 33 votes

7 Comments »

Comments feed TrackBack URI

Just released modulr as a ruby gem. Updated the README accordingly.

To process a JavaScript source file, just run:

$ modulrize filename.js > output.js

Comment by tobielangel — March 8, 2010

Maybe 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.

Comment by Jaaap — March 8, 2010

@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?

Comment by ragjunk — March 8, 2010

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.

Comment by tobielangel — March 8, 2010

I can see the server side. Does it have client side as well? How is it different from sprockets?

Comment by icoloma — March 8, 2010

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.

Comment by tobielangel — March 8, 2010

This sounds just like sprockets. I guess I will have to dig in to see.

Comment by ksteigerwald — March 9, 2010

Leave a comment

You must be logged in to post a comment.