Skip to content

Commit

Permalink
Merge pull request #7798 from webpack/bugfix/empty-chunks-fail
Browse files Browse the repository at this point in the history
fix case where empty chunkgroups cause nested chunkgroups to vanish
  • Loading branch information
sokra committed Jul 27, 2018
2 parents a28f44f + aac4368 commit 6c60e9d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/Compilation.js
Expand Up @@ -1572,6 +1572,9 @@ class Compilation extends Tapable {
/** @type {Map<DependenciesBlock, ChunkGroup>} */
const blockChunkGroups = new Map();

/** @type {Set<DependenciesBlock>} */
const blocksWithNestedBlocks = new Set();

const ADD_AND_ENTER_MODULE = 0;
const ENTER_MODULE = 1;
const PROCESS_BLOCK = 2;
Expand Down Expand Up @@ -1731,6 +1734,10 @@ class Compilation extends Tapable {

// Traverse all Blocks
iterationOfArrayCallback(blockInfo.blocks, iteratorBlock);

if (blockInfo.blocks.length > 0 && module !== block) {
blocksWithNestedBlocks.add(block);
}
break;
}
case LEAVE_MODULE: {
Expand Down Expand Up @@ -1792,6 +1799,7 @@ class Compilation extends Tapable {
*/
const filterFn = dep => {
const depChunkGroup = dep.chunkGroup;
if (blocksWithNestedBlocks.has(dep.block)) return true;
if (areModulesAvailable(depChunkGroup, newAvailableModules)) return false; // break all modules are already available
return true;
};
Expand Down
Empty file.
1 change: 1 addition & 0 deletions test/cases/chunks/nested-in-empty/b.js
@@ -0,0 +1 @@
module.exports = 42;
13 changes: 13 additions & 0 deletions test/cases/chunks/nested-in-empty/index.js
@@ -0,0 +1,13 @@
it("should include a chunk nested in an empty chunk", (done) => {
require.ensure(["./a"], () => {
require.ensure([], () => {
require.ensure(["./a"], () => {
require.ensure([], () => {
const b = require("./b");
expect(b).toBe(42);
done();
});
});
});
});
});

0 comments on commit 6c60e9d

Please sign in to comment.