diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-08-14 05:01:11 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-08-14 05:02:09 +0200 |
commit | 363723fc84f7b8477592e0105aeb331ec9a017af (patch) | |
tree | 29f92724f34131bac64d6a318dd7e30612e631c7 /node_modules/webpack/lib/optimize/AggressiveMergingPlugin.js | |
parent | 5634e77ad96bfe1818f6b6ee70b7379652e5487f (diff) |
node_modules
Diffstat (limited to 'node_modules/webpack/lib/optimize/AggressiveMergingPlugin.js')
-rw-r--r-- | node_modules/webpack/lib/optimize/AggressiveMergingPlugin.js | 62 |
1 files changed, 28 insertions, 34 deletions
diff --git a/node_modules/webpack/lib/optimize/AggressiveMergingPlugin.js b/node_modules/webpack/lib/optimize/AggressiveMergingPlugin.js index 826a6baa9..dc14ac300 100644 --- a/node_modules/webpack/lib/optimize/AggressiveMergingPlugin.js +++ b/node_modules/webpack/lib/optimize/AggressiveMergingPlugin.js @@ -23,7 +23,7 @@ class AggressiveMergingPlugin { return a + b;
}, 0);
}
- compiler.plugin("compilation", (compilation) => {
+ compiler.plugin("this-compilation", (compilation) => {
compilation.plugin("optimize-chunks-advanced", (chunks) => {
let combinations = [];
chunks.forEach((a, idx) => {
@@ -31,86 +31,80 @@ class AggressiveMergingPlugin { for(let i = 0; i < idx; i++) {
const b = chunks[i];
if(b.isInitial()) continue;
- combinations.push([b, a]);
+ combinations.push({
+ a,
+ b,
+ improvement: undefined
+ });
}
});
combinations.forEach((pair) => {
- const a = pair[0].size({
+ const a = pair.b.size({
chunkOverhead: 0
});
- const b = pair[1].size({
+ const b = pair.a.size({
chunkOverhead: 0
});
- const ab = pair[0].integratedSize(pair[1], {
+ const ab = pair.b.integratedSize(pair.a, {
chunkOverhead: 0
});
- pair.push({
- a: a,
- b: b,
- ab: ab
- });
let newSize;
if(ab === false) {
- pair.unshift(false);
+ pair.improvement = false;
+ return;
} else if(options.moveToParents) {
const aOnly = ab - b;
const bOnly = ab - a;
const common = a + b - ab;
- newSize = common + getParentsWeight(pair[0]) * aOnly + getParentsWeight(pair[1]) * bOnly;
- pair.push({
- aOnly: aOnly,
- bOnly: bOnly,
- common: common,
- newSize: newSize
- });
+ newSize = common + getParentsWeight(pair.b) * aOnly + getParentsWeight(pair.a) * bOnly;
} else {
newSize = ab;
}
- pair.unshift((a + b) / newSize);
+ pair.improvement = (a + b) / newSize;
});
combinations = combinations.filter((pair) => {
- return pair[0] !== false;
+ return pair.improvement !== false;
});
combinations.sort((a, b) => {
- return b[0] - a[0];
+ return b.improvement - a.improvement;
});
const pair = combinations[0];
if(!pair) return;
- if(pair[0] < minSizeReduce) return;
+ if(pair.improvement < minSizeReduce) return;
if(options.moveToParents) {
- const commonModules = pair[1].modules.filter((m) => {
- return pair[2].modules.indexOf(m) >= 0;
+ const commonModules = pair.b.modules.filter((m) => {
+ return pair.a.modules.indexOf(m) >= 0;
});
- const aOnlyModules = pair[1].modules.filter((m) => {
+ const aOnlyModules = pair.b.modules.filter((m) => {
return commonModules.indexOf(m) < 0;
});
- const bOnlyModules = pair[2].modules.filter((m) => {
+ const bOnlyModules = pair.a.modules.filter((m) => {
return commonModules.indexOf(m) < 0;
});
aOnlyModules.forEach((m) => {
- pair[1].removeModule(m);
- m.removeChunk(pair[1]);
- pair[1].parents.forEach((c) => {
+ pair.b.removeModule(m);
+ m.removeChunk(pair.b);
+ pair.b.parents.forEach((c) => {
c.addModule(m);
m.addChunk(c);
});
});
bOnlyModules.forEach((m) => {
- pair[2].removeModule(m);
- m.removeChunk(pair[2]);
- pair[2].parents.forEach((c) => {
+ pair.a.removeModule(m);
+ m.removeChunk(pair.a);
+ pair.a.parents.forEach((c) => {
c.addModule(m);
m.addChunk(c);
});
});
}
- if(pair[1].integrate(pair[2], "aggressive-merge")) {
- chunks.splice(chunks.indexOf(pair[2]), 1);
+ if(pair.b.integrate(pair.a, "aggressive-merge")) {
+ chunks.splice(chunks.indexOf(pair.a), 1);
return true;
}
});
|