Search code examples
requirejsamd

What is the best way to configure an AMD/Require.js module before it is loaded into other modules?


Currently I am using Marionette which registers itself as an AMD module called "marionette". Before it gets loaded into other modules, I want to set some configurations on it. My only thought as of now is to do this:

// configuredMarionette.js
define(["marionette"], function(Marionette) {
    // modify Marionette here
    return Marionette;
});

Then, in each of my modules that need marionette, I set "configuredMarionette" as the dependency instead of "marionette" so that I get the configured version. Is there any other way around this that is cleaner?


Solution

  • It may be more useful if you rename 'configuredMarionette' to 'marionette' and use 'orignalMarionette' for original one.

    It will be easy to use any other module which has a dependency to 'marionette' to use configured one.