new require(id) → {*}
The synchronously executing require function. Can only be
used for static dependencies, or dependencies that have already
been loaded. If you wish to require a module where the ID is
only known at runtime, use require.async.
Parameters:
| Name | Type | Description |
|---|---|---|
id |
string | The id of the module to require. |
- Source:
- require.js, line 278
Returns:
The exports of the module.
- Type
- *
Example
var URL = require("mini-url");
var other = URL.resolve("http://example.com/path", "../other");
//...
Members
-
<static> config :Object
-
The configuration for this package/require.
Type:
- Object
- Source:
- require.js, line 479
Methods
-
<static> async(id) → {Promise.<*>}
-
Asynchronous
requirefunction. Can be used to dynamically load a dependency at runtime.Parameters:
Name Type Description idstring The id of the module to require.
- Source:
- require.js, line 297
Returns:
A promise for the exports of the module.
- Type
- Promise.<*>
Example
require.async("mini-url") .then(function (URL) { var other = URL.resolve("http://example.com/path", "../other"); //... }) .done(); -
<static> deepLoad(id) → {Promise}
-
Loads a module definition and the definitions of its transitive dependencies.
Parameters:
Name Type Description idstring The module id to load.
- Source:
- require.js, line 353
Returns:
A promise for the completion of the loading of the module and its dependencies.
- Type
- Promise
-
<static> getModuleDescriptor(id) → {Object}
-
Gets the module descriptor for the given id.
The module descriptor is the value of the
modulefree variable given inside the corresponding module.Parameters:
Name Type Description idstring The id to get the module descriptor for.
- Source:
- require.js, line 331
Returns:
The module descriptor.
- Type
- Object
-
<static> getPackage(dependency) → {require}
-
Gets the
requirefor the diven package dependency.The package must have been loaded (for example with
require.loadPackage) prior to calling this function.Parameters:
Name Type Description dependencygivenDependency The package dependency to get.
- Source:
- require.js, line 404
Returns:
The package's
require.- Type
- require
-
<static> hasPackage(dependency) → {boolean}
-
Returns if this package has the given package dependency loaded.
Parameters:
Name Type Description dependencygivenDependency The package dependency to check.
- Source:
- require.js, line 391
Returns:
trueif the package has been loaded,falseif not.- Type
- boolean
-
<static> inject(id, exports)
-
Directly inject the exports for the given module id.
Useful to prevent wasteful multiple instantiation if a module was loaded in the bootstrapping process and can be trivially injected into the system.
Parameters:
Name Type Description idstring The module id to inject exports for.
exports* The exports of the module.
- Source:
- require.js, line 469
-
<static> injectDependency(name)
-
Inject a dependency, as if it was listed in the
package.json'sdependencyblock.Parameters:
Name Type Description namestring The name of the dependency.
- Source:
- require.js, line 452
-
<static> injectMapping(dependency, name)
-
Injects a mapping into this
require.Parameters:
Name Type Description dependencygivenDependency The dependency to use for
name.namestring The name of the mapping.
- Source:
- require.js, line 441
-
<static> injectPackageDescription(location, description)
-
Injects a package description directly into this
require.Parameters:
Name Type Description locationstring The absolute path to the package.
descriptionDescription The package description, as would usually be found in a
package.json.- Source:
- require.js, line 423
-
<static> injectPackageDescriptionLocation()
-
Injects the location of a package decription into this
require. TODO- Source:
- require.js, line 431
-
<static> isMainPackage() → {boolean}
-
Returns if this is the top-most package of this
require.- Source:
- require.js, line 412
Returns:
- Type
- boolean
-
<static> load(id) → {Promise}
-
Ensures a module definition is loaded, compiled, analyzed.
Note: this just loads the module. To load its dependencies as well use
require.deepLoad.Uses the loader created by
config.makeLoader.Parameters:
Name Type Description idstring The module id to load.
- Source:
- require.js, line 344
Returns:
A promise for the completion of the loading.
- Type
- Promise
-
<static> loadPackage(dependency, givenConfig) → {Promise.<require>}
-
Loads a package.
If givenConfig is not provided then the package is loaded as a child of this package (which is probably what you want). Otherwise the package is loaded with no parent, behaving the same as
Require.loadPackage.Parameters:
Name Type Argument Description dependencygivenDependency The dependency to load.
givenConfigObject <optional>
The parent configuration to use.
- Source:
- require.js, line 377
Returns:
A
requirefunction for the root of the package.- Type
- Promise.<require>
Example
require.loadPackage({ name: "q" }) .then(function (qRequire) { return qRequire.async("queue"); }) .then(function (queue) { //... }) .done(); -
<static> read(location) → {Promise.<string>}
-
Low level function that reads a location.
In the browser the location should be a url, and in node it should be a path.
Parameters:
Name Type Description locationstring The location to read.
- Source:
- require.js, line 492
Returns:
A promise for the string contents of the file at
location.- Type
- Promise.<string>
-
<static> resolve(id) → {string}
-
Removes any "." and ".." parts from the given id, the ".js" extension if it exists and, if relative, makes absolute from the base ID of the require.
Parameters:
Name Type Description idstring The id of the module to resolve.
- Source:
- require.js, line 316
Returns:
The resolved module id.
- Type
- string
Example
// in my/sub/module require.resolve("../other/./sub/module") // -> my/other/sub/module