Attempt to list some possible standard AMD loader configuration values.
An AMD loader is not required to implement all of these configuration values, but if it does provide a capability that is satisfied by these configuration values, it should use these configuration values and structures.
String: Indicates the root used for ID-to-path resolutions. Relative paths are relative to the current working directory. In web browsers, the current working directory is the directory containing the web page running the script.
Example:
{
baseUrl: './foo/bar'
}
Object. A property in the object is an absolute module ID prefix, and the value can either be a String or Object that indicates properties to give to module IDs that start with the ID prefix.
Values can be either:
- String: a path value to use for the module ID prefix. If it is a relative path, it it relative to baseUrl. It can be an absolute path, like
/top/level/dir
or ``//top/level/diror
http://some.domain.com/top/level/dir`. - Object: an object that can have the following properties:
- location: String. Optional. a path value to use for the module ID prefix. Behaves the same as if a String is used for that paths value.
- map: Object. Optional. See [details under the map section.
Array of package configuration (packageConfig) objects. Package configuration is for traditional CommonJS packages, which has different path lookup rules than the default ID-to-path lookup rules used by a loader.
Default lookup rules are ,baseUrl + 'module/id' + .js
, where paths config can be used to map part of
'module/id'
to another path.
Package lookup rules use a special lookup rule when 'packageName' is used.
For the "main module" of a package, instead of it being
baseUrl + 'packageName' + '.js'
, it is:
baseUrl + (packageConfig.location || 'packageName') + '/' + (packageConfig.main || 'main') + '.js'
For 'packageName/otherId', the rule is similar to paths, but packageConfig is used instead:
baseUrl + (packageConfig.location || 'packageName') + '/' + 'otherId' + '.js'
The package configuration object can either be:
-
String: The first segment of an absolute module ID, which indicates the package name. So, for a module ID of
some/thing/here
, the first segment of the module ID issome
. In that examplesome
is the package name, and the value used for this config value. -
Object: a configuration object that can have the following properties:
- name: String. first segment of an absolute module ID (see String section immediately above).
- location: String. Optional.
- main: The module ID to use inside the package for the "main module".
- map: Object. Optional. See [details under the map section.
packages: [ { name: 'dojo', location: 'dojo/1.7.1', main:'main' } ]
Object. This property is available under a paths or packages config value. It specifies an internal map to use for dependencies under that paths/packages config. The property name is a module prefix. Only the first segment of a module prefix is allowed. The property value is a string that mentions which top level module ID prefix to use instead of the property name.
Example:
Example:
{
paths: {
'some/thing': {
map: {
'c': 'c-1'
}
}
}
}
For modules whose absolute ID starts with 'some/thing', if they have a dependency on anything whose absolute ID starts with 'c/', treat it as an ID that starts with 'c-1/' instead.
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.
Example:
{
config: {
'some/module/id': {
limit: 40
}
}
}
For the module that resolves to the absolute module ID of 'some/module/id', module.config.limit === 40
While it is nice to be able to remap entire paths, it would be good to be able to specify something like:
or
This way, if I do:
It resolves to
moduleGroup.min.js
and notmoduleGroup.min/A.js
Maybe the
map
property can solve this by doing something like: