diff options
Diffstat (limited to 'node_modules/webpack/lib/optimize/CommonsChunkPlugin.js')
-rw-r--r-- | node_modules/webpack/lib/optimize/CommonsChunkPlugin.js | 51 |
1 files changed, 36 insertions, 15 deletions
diff --git a/node_modules/webpack/lib/optimize/CommonsChunkPlugin.js b/node_modules/webpack/lib/optimize/CommonsChunkPlugin.js index 3ef414198..465b7ff7a 100644 --- a/node_modules/webpack/lib/optimize/CommonsChunkPlugin.js +++ b/node_modules/webpack/lib/optimize/CommonsChunkPlugin.js @@ -60,8 +60,8 @@ The available options are: * that webpack will take care of loading this file.
*/
if(options.async && options.filename) {
- throw new Error(`You can not specify a filename if you use the \"async\" option.
-You can however specify the name of the async chunk by passing the desired string as the \"async\" option.`);
+ throw new Error(`You can not specify a filename if you use the "async" option.
+You can however specify the name of the async chunk by passing the desired string as the "async" option.`);
}
/**
@@ -115,7 +115,18 @@ You can however specify the name of the async chunk by passing the desired strin // override the "commonChunk" with the newly created async one and use it as commonChunk from now on
let asyncChunk;
if(this.async) {
- asyncChunk = this.createAsyncChunk(compilation, this.async, targetChunk);
+ // If async chunk is one of the affected chunks, just use it
+ asyncChunk = affectedChunks.filter(c => c.name === this.async)[0];
+ // Elsewise create a new one
+ if(!asyncChunk) {
+ asyncChunk = this.createAsyncChunk(
+ compilation,
+ targetChunks.length <= 1 || typeof this.async !== "string" ? this.async :
+ targetChunk.name ? `${this.async}-${targetChunk.name}` :
+ true,
+ targetChunk
+ );
+ }
targetChunk = asyncChunk;
}
@@ -190,7 +201,7 @@ You can however specify the name of the async chunk by passing the desired strin // we dont have named chunks specified, so we just take all of them
if(asyncOrNoSelectedChunk) {
- return allChunks.filter(chunk => !chunk.isInitial());
+ return allChunks;
}
/**
@@ -218,8 +229,15 @@ Take a look at the "name"/"names" or async/children option.`); }
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
- return asyncOption || chunk.parents.length === 1;
+ if(!asyncOption)
+ return chunk.parents.length === 1;
+
+ return true;
});
}
@@ -275,7 +293,7 @@ Take a look at the "name"/"names" or async/children option.`); // count how many chunks contain a module
const commonModulesToCountMap = usedChunks.reduce((map, chunk) => {
- for(let module of chunk.modules) {
+ for(const module of chunk.modulesIterable) {
const count = map.has(module) ? map.get(module) : 0;
map.set(module, count + 1);
}
@@ -306,7 +324,7 @@ Take a look at the "name"/"names" or async/children option.`); extractModulesAndReturnAffectedChunks(reallyUsedModules, usedChunks) {
return reallyUsedModules.reduce((affectedChunksSet, module) => {
- for(let chunk of usedChunks) {
+ for(const chunk of usedChunks) {
// removeChunk returns true if the chunk was contained and succesfully removed
// false if the module did not have a connection to the chunk in question
if(module.removeChunk(chunk)) {
@@ -318,29 +336,32 @@ Take a look at the "name"/"names" or async/children option.`); }
addExtractedModulesToTargetChunk(chunk, modules) {
- for(let module of modules) {
+ for(const module of modules) {
chunk.addModule(module);
module.addChunk(chunk);
}
}
makeTargetChunkParentOfAffectedChunks(usedChunks, commonChunk) {
- for(let chunk of usedChunks) {
+ for(const chunk of usedChunks) {
// set commonChunk as new sole parent
chunk.parents = [commonChunk];
// add chunk to commonChunk
commonChunk.addChunk(chunk);
- for(let entrypoint of chunk.entrypoints) {
+ for(const entrypoint of chunk.entrypoints) {
entrypoint.insertChunk(commonChunk, chunk);
}
}
}
moveExtractedChunkBlocksToTargetChunk(chunks, targetChunk) {
- for(let chunk of chunks) {
- for(let block of chunk.blocks) {
- block.chunks.unshift(targetChunk);
+ for(const chunk of chunks) {
+ if(chunk === targetChunk) continue;
+ for(const block of chunk.blocks) {
+ if(block.chunks.indexOf(targetChunk) === -1) {
+ block.chunks.unshift(targetChunk);
+ }
targetChunk.addBlock(block);
}
}
@@ -348,8 +369,8 @@ Take a look at the "name"/"names" or async/children option.`); extractOriginsOfChunksWithExtractedModules(chunks) {
const origins = [];
- for(let chunk of chunks) {
- for(let origin of chunk.origins) {
+ for(const chunk of chunks) {
+ for(const origin of chunk.origins) {
const newOrigin = Object.create(origin);
newOrigin.reasons = (origin.reasons || []).concat("async commons");
origins.push(newOrigin);
|