Skip to content
jrburke edited this page Aug 30, 2011 · 6 revisions

Loader plugins allow extending an AMD implementation by allowing loading of resources that are not traditional JavaScript dependencies.

The API is designed to allow running a loader plugin as part of an optimization tool so that some kinds of plugin resources to be inlined if it makes sense for that type of loader plugin to do so. Because of this capability, a loader plugin should be coded to be able to run in many kinds of JavaScript environments, like the browser, Node and/or Rhino.

API Specification

Terms

A plugin dependency is a dependency expressed in AMD that is intended to be loaded by a loader plugin. It has the form:

[Plugin Module ID]![resource ID]

where plugin module ID is a normal AMD module ID that indicates the JavaScript module that implements the loader plugin API, and resource ID is a plugin-specific string that the loader plugins knows how to parse to load the resource.

Examples of a plugin dependencies

Here is one that uses a text loader plugin to load an HTML template.

define(['text!../templates/start.html'], function (template) {
    //do something with the template text string.
});

Here is another one that has a more complex resource ID structure. It is a bit of a contrived example. It just chooses the module name that is part of the resource ID that matches to the array index given by the first number in the resource ID. So the impl below would be the module represented by './b':

define(function (require) {
    var impl = require('index!1:./a:./b:./c');
});
Clone this wiki locally