Skip to content

Migrating old projects from amd utils

millermedeiros edited this page Jan 14, 2013 · 2 revisions

AMD is a very flexible format, v0.1.0 of mout follows exactly the same API and modules as amd-utils v0.10.0 so migration should be very straightforward.

RequireJS supports the map setting, which is used to map module IDs to a different location, you can create an alias to amd-utils to make sure all legacy code find the proper mout module like:

requirejs.config({
  map : {
    "*" : {
      "amd-utils" : "mout"
    }
  }
});

After setting the map config all modules that required any "amd-utils" module will now use "mout" instead:

// legacy_module.js
define(['amd-utils/math/clamp'], function(clamp){
  // will load "mout/math/clamp" instead of "amd-utils/math/clamp"
  clamp(17, 0, 10);
  ...
});

Another option is to simply rename the mout/src folder to amd-utils, since we only use unnamed modules things should just work. AMD FTW!

Find and Replace

Doing a find and replace across the whole project should not be that hard:

find . -name "*.js" -exec sed -i "" 's/amd-utils/mout/g' {} \;
Clone this wiki locally