D
D
Dima Barsukov2016-02-02 15:00:29
JavaScript
Dima Barsukov, 2016-02-02 15:00:29

Why specify dependencies in webpack require.ensure?

In the webpack dock, when creating a chunk, it is possible to specify dependencies. The idea of ​​writing a dependency is not entirely clear, if everything in the callback is requested via require, it will fall into the chunk.
That is, what is the difference

require.ensure(['jquery'], function(require) {
  require("jquery");
});

и

require.ensure([], function(require) {
  require("jquery");
})

Can someone explain? Or maybe it's important, but I'm missing something.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
_
_ _, 2016-02-02
@AMar4enko

This is necessary for asynchronous loading of chunks.
The dependencies that you describe in the first parameter will be taken out of the bundle into separate chunks that will be downloaded on request.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question