Add feature similar to require.ensure, but call it require.async.
Example input
const libA = require("./lib-a");
require.async(["./lib-b", "./lib-c"], function (libB, libC) {
// ...
});
Example output
{
'aaaaaa': {
deps: [],
fn: function (require, module, exports) {
var libA = require("bbbbbb")
require.async("cccccc"/*["dddddd", "eeeeee"]*/, function (libB, libC) {
// ...
});
}
},
'bbbbbb': {
deps: [],
fn: function (require, module, exports) {
module.exports = "libA";
}
},
'cccccc': {
deps: ["dddddd", "eeeeee"],
fn: function (require, module, exports) {
module.exports = function (cb) {
cb(require("dddddd"), require("eeeeee"));
};
}
},
'dddddd': {
deps: [],
fn: function (require, module, exports) {
module.exports = "libB";
}
},
'eeeeee': {
deps: [],
fn: function (require, module, exports) {
module.exports = "libC";
}
}
}
When the require.async is invoked within the example module, the Interlock will call the cccccc module as if it were an entry point - first ensuring that all dependencies are installed and invoked, resolving/installing/invoking any missing dependencies, and finally calling the cccccc module itself. This module's exports will be a function that invokes a callback, requiring and passing constituent dependencies as parameters.
The require.async implementation will have recorded the callback passed to it, and pass that to cccccc's returned function when available.
Add feature similar to
require.ensure, but call itrequire.async.require(...)calls.require.asynchas no effect on splitting. That is still managed by the build config itself.require.async(or compiled equivalent) is invoked at run-time, 1) modules are resolved and invoked, 2) callback is invoked with params matching therequired modules.Example input
Example output
When the
require.asyncis invoked within the example module, the Interlock will call theccccccmodule as if it were an entry point - first ensuring that all dependencies are installed and invoked, resolving/installing/invoking any missing dependencies, and finally calling theccccccmodule itself. This module's exports will be a function that invokes a callback, requiring and passing constituent dependencies as parameters.The
require.asyncimplementation will have recorded the callback passed to it, and pass that tocccccc's returned function when available.