diff options
Diffstat (limited to 'node_modules/webpack/lib/optimize/CommonsChunkPlugin.js')
-rw-r--r-- | node_modules/webpack/lib/optimize/CommonsChunkPlugin.js | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/node_modules/webpack/lib/optimize/CommonsChunkPlugin.js b/node_modules/webpack/lib/optimize/CommonsChunkPlugin.js index 465b7ff7a..ab7b69f4a 100644 --- a/node_modules/webpack/lib/optimize/CommonsChunkPlugin.js +++ b/node_modules/webpack/lib/optimize/CommonsChunkPlugin.js @@ -4,6 +4,7 @@ */
"use strict";
let nextIdent = 0;
+
class CommonsChunkPlugin {
constructor(options) {
if(arguments.length > 1) {
@@ -31,6 +32,7 @@ The available options are: this.minChunks = normalizedOptions.minChunks;
this.selectedChunks = normalizedOptions.selectedChunks;
this.children = normalizedOptions.children;
+ this.deepChildren = normalizedOptions.deepChildren;
this.async = normalizedOptions.async;
this.minSize = normalizedOptions.minSize;
this.ident = __filename + (nextIdent++);
@@ -76,6 +78,7 @@ You can however specify the name of the async chunk by passing the desired strin minChunks: options.minChunks,
selectedChunks: options.chunks,
children: options.children,
+ deepChildren: options.deepChildren,
async: options.async,
minSize: options.minSize
};
@@ -211,6 +214,37 @@ You can however specify the name of the async chunk by passing the desired strin Take a look at the "name"/"names" or async/children option.`);
}
+ getAffectedUnnamedChunks(affectedChunks, targetChunk, asyncOption) {
+ let chunks = targetChunk.chunks;
+ chunks && chunks.forEach((chunk) => {
+ if(chunk.isInitial()) {
+ return;
+ }
+ // If all the parents of a chunk are either
+ // a) the target chunk we started with
+ // b) themselves affected chunks
+ // we can assume that this chunk is an affected chunk too, as there is no way a chunk that
+ // isn't only depending on the target chunk is a parent of the chunk tested
+ if(asyncOption || chunk.parents.every((parentChunk) => parentChunk === targetChunk || affectedChunks.has(parentChunk))) {
+ // This check not only dedupes the affectedChunks but also guarantees we avoid endless loops
+ if(!affectedChunks.has(chunk) || affectedChunks.values().next().value === chunk) {
+ // We mutate the affected chunks before going deeper, so the deeper levels and other branches
+ // Have the information of this chunk being affected for their assertion if a chunk should
+ // not be affected
+ affectedChunks.add(chunk);
+
+ // We recurse down to all the children of the chunk, applying the same assumption.
+ // This guarantees that if a chunk should be an affected chunk,
+ // at the latest the last connection to the same chunk meets the
+ // condition to add it to the affected chunks.
+ if(this.deepChildren === true) {
+ this.getAffectedUnnamedChunks(affectedChunks, chunk, asyncOption);
+ }
+ }
+ }
+ });
+ }
+
getAffectedChunks(compilation, allChunks, targetChunk, targetChunks, currentIndex, selectedChunks, asyncOption, children) {
const asyncOrNoSelectedChunk = children || asyncOption;
@@ -223,22 +257,9 @@ Take a look at the "name"/"names" or async/children option.`); }
if(asyncOrNoSelectedChunk) {
- // nothing to do here
- if(!targetChunk.chunks) {
- return [];
- }
-
- return targetChunk.chunks.filter((chunk) => {
- // we only are interested in on-demand chunks
- if(chunk.isInitial())
- return false;
-
- // we can only move modules from this chunk if the "commonChunk" is the only parent
- if(!asyncOption)
- return chunk.parents.length === 1;
-
- return true;
- });
+ let affectedChunks = new Set();
+ this.getAffectedUnnamedChunks(affectedChunks, targetChunk, asyncOption);
+ return Array.from(affectedChunks);
}
/**
|