metajack/strophejs — Issue #66: AMD modulization support
Author: taybin
Created: 2011-10-27 14:57:56+00:00
State: open

[AMD modules](https://github.com/amdjs/amdjs-api/wiki/AMD) are an increasingly popular way to prevent namespace pollution. It would be great if Strophe could be packaged with support for this.

The code for this can be as simple as:
```javascript
var args = arguments;
if ( typeof define === 'function' && define.amd ) {
// register with AMD as a module
define( function () {
var Strophe = args[0];
Strophe.$build = args[1];
Strophe.$msg = args[2];
Strophe.$iq = args[3];
Strophe.$pres = args[4];

return Strophe;
});
} else {
window.Strophe = arguments[0];
window.$build = arguments[1];
window.$msg = arguments[2];
window.$iq = arguments[3];
window.$pres = arguments[4];
}
```

The only remaining problem is how to package MD5 and Base64? They can either be wrapped into their own modules, in which case they [need to be distributed in their own files](http://requirejs.org/docs/api.html#modulenotes), or they can be [compiled together](http://requirejs.org/docs/faq-optimization.html#wrap) using r.js.

That seems like a big change to the build system though, so I'm a little stuck on what would be appropriate here.