In short: you do not have to worry.
Origin of the problem
Tobias Coppers, author of Webpack, was asked a similar question on Gitter :
Raul Ferra : Is there any advantage between these two forms?
require.ensure(['jquery','Backbone','underscore'], function(require){ var jQuery = require('jquery'), Backbone = require('Backbone'), _ = require('underscore'); };
and this one
require.ensure(['jquery'], function(require){ var jQuery = require('jquery'), Backbone = require('Backbone'), _ = require('underscore'); };
Tobias Koppers : no difference ... even the generated source is equal. But the spec says that the dependency should be in an array.
Webpack require.ensure
been implemented as proposed by CommonJS Modules / Async / A , which states:
"require.ensure" takes an array of module identifiers as the first argument and a callback function as the second argument.
The specification does not indicate whether there will be loadable asynchronously loaded modules that are not listed, but there is an example code that requires only the module specified in the array:
require.ensure(['increment'], function(require) { var inc = require('increment').inc; var a = 1; inc(a);
Thus, in my opinion, asynchronous loading of require
d, but not the listed modules, is a feature of Webpack and a deviation from the specification. This feature makes the first argument meaningless in most cases and raises questions.
Use cases
1. Follow the specification
One option for using the first argument is to specify all the dependencies for clarity and specification. But this is completely optional.
2. Pull the modules into specific pieces
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: