The first parameter is rarely used. To find out why it exists and is causing confusion, see My other answer.
Follow specification
One use case for the first parameter may be to specify all the dependencies for clarity and match the spec . But this is completely optional.
Add modules to pieces to make pieces look like
You have two split points in different parts of the application. The first separation point depends on the module a , the second depends on the modules a and b . To eliminate the risk of loading a twice, you can decide to place both modules in one piece:
// First split point require.ensure(['b'], (require) => { require('a'); });
Pull modules into original pieces
Consider the following code splitting scenario:
require.ensure([], (require) => { ... require.ensure([], (require) => { require('a'); require('b'); }); require.ensure([], (require) => { require('a'); require('c'); }); ... });
In this case, the module a will appear in both nested pieces. If at least one of the nested chunks is often loaded, you can move a to the parent chunk:
require.ensure(['a'], (require) => { ...
Add modules to pieces using require.include
Consider the previous example. Another way to pull a into the parent piece:
require.ensure([], (require) => { require.include('a'); ...
In this specific example, both solutions are equivalent, and there is no benefit when using require.include . However, if you do not have access to the code with a separating point, the parent chunk is an input fragment, or you use the modern import() syntax, your choice is require.include .
You can pull modules into pieces using synchronous require or import . The advantage of require.include is that it only loads modules and does not evaluate them. This can be useful for delaying the evaluation of modules if it is expensive or depends on the state of the application, for example, requires loading polyfill, DOM nodes, etc.