Creating AMD-compatible requirejs modules

I am currently creating an application in which the interface does a lot of hard work. To keep everything neat and organized, I would like to use requirejs . However, to use require.js to the full, all the modules that I use must meet AMD requirements.

This means that every time the updated module is updated, I need to either wait for the appearance of the version compatible with AMD, or do it myself (which I do not currently know how to do).

This is a real rollback.

Looking at this https://github.com/jrburke/backbone/blob/optamd/backbone.js , it seems to me that creating a module such as AMD's Backbone is not as simple as wrapping a plugin in a common function.

Is there a more or less simple way to make the module compatible with AMD?

+3
source share
1 answer

Well, its version is pretty bulletproof, so it will work in a variety of circumstances. Since you know the environment in which you work, and what is available / what is not, you can make some assumptions that will allow you to do something more straightforward.

gist, bacbkonejs AMD, jQuery, , commonjs: https://gist.github.com/2762813

define(function() {
  var obj = {};
  obj._ = window._;
  obj.jQuery = window.jQuery;

.call(obj);
   return obj.Backbone;
});

.


@SimonSmith UseJS . UseJS - AMD, AMD . , : https://github.com/tbranyen/use.js/

UPDATE

RequireJS 2.0 , , shim: https://github.com/jrburke/requirejs/wiki/Upgrading-to-RequireJS-2.0#wiki-shim

+2

All Articles