Issue 1:
I found an example where webpack struggles to avoid dependency duplication. See below, where c.js is the entry point.

// c.js

function getMeAModule(moduleName) {
if (moduleName === 'a') {
require.ensure(['a'], function (require) {
var a = require('a');
a();
});
}
if (moduleName === 'b') {
require.ensure(['b'], function (require) {
var b = require('b');
b();
});
}
}

window.getMeAModule = getMeAModule;

// a.js

var d = require('d');

module.exports = function () {
d();
console.log('a');
};

// b.js

var d = require('d');

module.exports = function () {
d();
console.log('b');
};

// d.js

module.exports = function () {
console.log('d');
};

If you build this example with webpack, three chunks will be created. The first will contain the entry point, c.js, as you would expect. The second "normal" chunk will contain a.js as well as d.js, and the third "normal" chunk will contain b.js and d.js.

It seems to me that in the ideal situation, I could run getMeAModule('a') in the console, and then subsequently run getMeAModule('b') in the console but before webpack sends the async request for the chunk containing b, it checks (on the client) to see that b's dependency on d is already satisifed, and performs a smarter async request.

I'm finding this to be quite problematic on a big project with a complicated dependency graph, large modules, and a dynamic require statement (which we currently work around with a long series of if-blocks, as in this example). Is webpack equipped to handle this situation? If so, how best can I do so?

Thanks for your help! :)

Issue 2:
I'm having troubles with nested split points and common chunk plugin. This is the module layout in a minimal example.

MODULES:

a,b,c,d,e: Leaf modules. You can see them as unrelated pieces of library code.

common: Common module. It just contains the explicit requires of what i want to be in a common chunk. In this case a, b and c.

app: It defines two split point for subapp_1 and subapp_2 via require.ensure

index: It defines two split point for loading common and app via require.ensure

subapp_1: requires a and d

subapp_2: requires b, c and e

I expect output of the build to have these chunks:

- main chunk that calls the `require.ensure` for `common` and `app` chunks
- a `common` chunk with `a`, `b` and `c` code
- an `app` chunk that calls the `require.ensure` for `subapp_1` and `subapp2`
- a `subapp_1` chunk that has only the `d` code
- a `subapp_2` chunk that hase only the `e` code

What i obtain is the same result but looks like webpack is not able to understand that subapp_1 and subapp_2 only need the bits that are not in the common chunk.

- main chunk that calls the `require.ensure` for `common` and `app` chunks
- a `common` chunk with `a`, `b` and `c` code
- an `app` chunk that calls the `require.ensure` for `subapp_1` and `subapp2`
- a `subapp_1` chunk that has `a` code and `d` code
- a `subapp_2` chunk that has `b`, `c` and `e` code

Am i missing something here?

The test case is attached to the issue and you can run it just with:

npm install
./node_modules/.bin/webpack

The resulting build is gonna be in:

./build

You can find the auto contained example here:

https://www.dropbox.com/s/7oteeky864cb219/splitpoint_test.zip?dl=0