ResourceLoader/Package files

A package module is a type of ResourceLoader module that consists of multiple script or data files, specified using the  property, which can be accessed separately using. Regular modules can have multiple script files in the  property, but these will be concatenated and will not be separately accessible.

How it works
A package file can either be JavaScript code (script), or a JSON blob (data). A file's type is inferred based on its extension ( or  ). Files can be real files or the file system, or dynamic files generated by code.

Every module has one main file. When the module loads, only the code in the main file is executed. The code in the other files is not executed unless and until it is invoked using.

To invoke a non-main file, use. The path must start with  or   to indicate that it's a file in the same module (as opposed to the name of another module), and the path must be relative to the current file. The return value of   is the value that foo.js assigns to.

Module definition
Files can be specified in the  property in the following ways:


 * will load a file from the filesystem
 * will load the file  from the file system, but its alias will be   (meaning it will be called that for the purposes of  )
 * defines a dynamic file called, with the specified contents
 * defines a dynamic file whose contents are
 * defines a dynamic file whose contents are the result of executing the callback
 * You can also specify a static function as a callback:  will call
 * For JS files, the callback should return a string. For JSON files, it can return anything that's JSON-serializable (typically an associative array)
 * defines a dynamic file whose contents are