Repository navigation
Internal API: onResourceLoad
RequireJS has an internal hook that can be used to get notifications of when a module is created/has an exports value, so that it is possible to trace the modules and their dependencies.
This is considered a private API, subject to change at any time. If you build on it, it is best to contact the requirejs list, and add your name below so that you can be notified of changes.
Note that you will only be notified about changes to the call signature for onResourceLoad, and not about changes to the arguments that are passed to the function. By using this API, you are signing up for future maintenance and changes. It is best if you start watching the commits to the project to make sure they do not affect you.
This API is used by the requirejs optimizer to trace dependencies for a build.
Create a file that implements the following signature:
requirejs.onResourceLoad = function (context, map, depArray) {
}You do not need to return any value from the function. The return value is not used by RequireJS.
Arguments to onResourceLoad:
Object. This is the internal state object used by RequireJS to store all exported values and loader state. You can mostly ignore it.
Object. This is information about the module ID for the module that just came into existence. Properties on this object:
- prefix: String. The name/module ID of any loader plugin that was used for this resource. It will be a normalized name -- an absolute ID, not a relative ID. This value will be null for a plain JS module.
- name: String. The normalized name (it will be an absolute ID, not a relative ID) for this module. If this is a plugin resource, it is just the plugin resource name.
- parentMap: Object. The map object used to resolve a relative ID for this module. Can be null, but if it exists it has the same structure as this map object.
- url: String. The URL used to retrieve the resource. It may be a relative path.
-
originalName: String. The original name of the module as it was loaded. For the module ID of a newly created module, this is likely the same as
fullName. -
fullName: String. This is
prefix!nameif there is aprefixvalue, otherwise justname. In RequireJS 2.0 this property is called id.
Array. An array of dependencies that were specified for the module. Each item of the array is a string that is the normalized name (the absolute module ID, not a relative ID) of the dependency. In RequireJS 2.0 each item of the array is a map object.
Load this file after require.js has been loaded. You can either do that via a script tag, or make sure it is the first thing loaded before other modules are traversed:
That should be it. Your implementation of onResourceLoad should be triggered for each module that is loaded and executed.
In RequireJS 2.0 there is no priority config anymore. Just manually load it in your main file before loading the other modules:
require(['onResourceLoad'], function () {
//Do normal main loading now.
require([], function () {});
});Add your name in this section if you want to be notified to changes in this API.
Taka Kojima ([email protected])
Ryan Leach ([email protected])
Rob Eisenberg ([email protected])
Guy Bedford ([email protected])
Burkhard Reffeling ([email protected])
Duncan Wong ([email protected])
Jason Strimpel ([email protected])
Ean Schuessler ([email protected])
Steven Devijver (sdevijver [ta] gmail [tod] com)
Pekka Lampila ([email protected])
Mariusz Linkiewicz ([email protected])
Denes Papp ([email protected])
Brian Wyant ([email protected])
Steve Mason ([email protected])
Jason Mobley ([email protected])
Andrew Wheelwright ([email protected])
iThome Taiwan ([email protected])
Dave Varon ([email protected])
Mateo San Roman ([email protected])
Facundo Cabrera ([email protected])
Andrew Smith ([email protected])
Bill Trikalinos ([email protected])
James Whitney ([email protected])
Ben Babics ([email protected])
Ryan Gray ([email protected])
Matthew Garber ([email protected])
Geoff Jacobsen ([email protected])
Lee Goddard ([email protected])
Andriy Mykulyak ([email protected])
Anup Bishnoi ([email protected])
Arvind Bhardwaj ([email protected])
Xavier Zwirtz([email protected])
Michael Roth([email protected])
Philip Plekhanov([email protected])
Alexey Babik ([email protected])
Fahim Farook ([email protected])
Kirill Berezin ([email protected])
Rob Simpson ([email protected])
Evgeny Vyushin ([email protected])
Thomas Sörensen ((scaryxited [ta] gmail [tod] com))
Chetan Raj ([email protected])
Pablo Sande ([email protected])
Emil Ajdyna ([email protected])
Dmitry Grechka ([email protected])
Pwn ([email protected])
Josh Goldberg ([email protected])
David Jordan ([email protected])