Skip to content

Configuring the AMD Optimizer Loader

rbackhouse edited this page Nov 16, 2012 · 6 revisions

Configuring the AMD Optimizer Loader

The loader supports the following configuration options within the configuration object passed to the zazl entry point call :

  • baseUrl Root path used to locate modules. Defaults to "./".
  • injectUrl URL path for the server-side javascript servlet/handler. Defaults to "_javascript".
  • directInject Boolean used to indicate if script injection should be used for the initial request. Defaults to false.
  • paths Path mappings via name/value pairs.
  • packages An array of package objects, each of which contain a "name", "location" and "main" property. The "name" is used for module name/prefix mappings, the "location" is the real path and the "main" property is the name of the module substituted when the package name is a dependency. "location" is optional, it defaults to the "name" value if not provided. "main" is also optional and like "location" defaults to the "name" value if ommited.
  • config A configuration object available to modules that match the absolute module ID listed in the config object. Modules with a matching module ID can access the configuration object via module.config, which is an Object value. The Object value is mutable. Modules can access this config by asking for module.config() when using the special module dependency
  • map Object. Specifies for a given module ID prefix, what module ID prefix to use in place of another module ID prefix. For example, how to express "when 'bar' asks for module ID 'foo', actually use module ID 'foo1.2'". See AMD Common Config (map) for more details
  • shim Object. Configure the dependencies and exports for older, traditional "browser globals" scripts that do not use define() to declare the dependencies and set a module value. Equivalent of the require.js shim configuration

e.g

zazl({
    baseUrl: './',
    injectUrl: '_javascript',
    directInject: true,
    packages: [
        {
            name: 'dojo',
            location: 'dojo',
            main:'main'
        },
        {
            name: 'dijit',
            location: 'dijit',
            main:'main'
        },
        {
            name: 'dojox',
            location: 'dojox',
            main:'main'
        }
    ],
    config : {
        'some/module/id' : {
            limit: 40
        }
    }
}, 
["my/Module"], 
function(mymodule) {
    console.log("done");
});

or you can create a zazlConfig global variable and use the global require entry point.

var zazlConfig = {
    baseUrl: './',
    injectUrl: '_javascript',
    directInject: true,
    packages: [
        {
            name: 'dojo',
            location: 'lib/dojo'
        },
        {
            name: 'dijit',
            location: 'lib/dijit'
        },
        {
            name: 'dojox',
            location: 'lib/dojox'
        }
    ],
    config : {
        'some/module/id' : {
            limit: 40
        }
    }
};

require(["my/Module"], function(mymodule) {
    console.log("done");
});

Here is an example of shim configuration

var zazlConfig = {
    paths: {
        jquery: '../lib/jquery/jquery-1.8.2',
        underscore: '../lib/underscore/underscore',
        backbone: '../lib/backbone/backbone'
    },
    shim: {
        'backbone' : {
            deps: ['underscore', 'jquery'],
            exports: 'Backbone'
        },
        'underscore' : {
            exports: '_'
        }
    }
};