webpack 1.13.3 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -22
- package/README.md +310 -310
- package/buildin/amd-define.js +1 -1
- package/buildin/amd-options.js +1 -1
- package/buildin/module.js +10 -10
- package/hot/dev-server.js +63 -63
- package/hot/log-apply-result.js +25 -25
- package/hot/only-dev-server.js +77 -77
- package/hot/poll.js +37 -37
- package/hot/signal.js +65 -65
- package/lib/APIPlugin.js +49 -49
- package/lib/AbstractPlugin.js +22 -22
- package/lib/AmdMainTemplatePlugin.js +43 -43
- package/lib/ArrayMap.js +50 -50
- package/lib/AsyncDependenciesBlock.js +39 -39
- package/lib/AutomaticPrefetchPlugin.js +35 -35
- package/lib/BannerPlugin.js +34 -34
- package/lib/BasicEvaluatedExpression.js +140 -140
- package/lib/CachePlugin.js +43 -43
- package/lib/CaseSensitiveModulesWarning.js +16 -16
- package/lib/Chunk.js +252 -252
- package/lib/ChunkRenderError.js +17 -17
- package/lib/ChunkTemplate.js +37 -37
- package/lib/CompatibilityPlugin.js +42 -42
- package/lib/Compilation.js +891 -891
- package/lib/Compiler.js +407 -407
- package/lib/ConcatSource.js +5 -5
- package/lib/ConstPlugin.js +54 -54
- package/lib/ContextModule.js +130 -130
- package/lib/ContextModuleFactory.js +132 -132
- package/lib/ContextReplacementPlugin.js +93 -93
- package/lib/CriticalDependenciesWarning.js +24 -24
- package/lib/DefinePlugin.js +126 -126
- package/lib/DelegatedModule.js +69 -69
- package/lib/DelegatedModuleFactoryPlugin.js +51 -51
- package/lib/DelegatedPlugin.js +21 -21
- package/lib/DependenciesBlock.js +57 -57
- package/lib/DependenciesBlockVariable.js +41 -41
- package/lib/Dependency.js +54 -54
- package/lib/DllEntryPlugin.js +32 -32
- package/lib/DllModule.js +55 -55
- package/lib/DllModuleFactory.js +18 -18
- package/lib/DllPlugin.js +30 -30
- package/lib/DllReferencePlugin.js +26 -26
- package/lib/EntryModuleNotFoundError.js +15 -15
- package/lib/EntryOptionPlugin.js +28 -28
- package/lib/EnvironmentPlugin.js +28 -28
- package/lib/EvalDevToolModulePlugin.js +17 -17
- package/lib/EvalDevToolModuleTemplatePlugin.js +29 -29
- package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +68 -68
- package/lib/EvalSourceMapDevToolPlugin.js +25 -25
- package/lib/ExtendedAPIPlugin.js +45 -45
- package/lib/ExternalModule.js +89 -89
- package/lib/ExternalModuleFactoryPlugin.js +86 -86
- package/lib/ExternalsPlugin.js +16 -16
- package/lib/FunctionModulePlugin.js +18 -18
- package/lib/FunctionModuleTemplatePlugin.js +39 -39
- package/lib/HotModuleReplacement.runtime.js +486 -486
- package/lib/HotModuleReplacementPlugin.js +223 -223
- package/lib/HotUpdateChunkTemplate.js +28 -28
- package/lib/IgnorePlugin.js +32 -32
- package/lib/JsonpChunkTemplatePlugin.js +26 -26
- package/lib/JsonpExportMainTemplatePlugin.js +28 -28
- package/lib/JsonpHotUpdateChunkTemplatePlugin.js +26 -26
- package/lib/JsonpMainTemplate.runtime.js +56 -56
- package/lib/JsonpMainTemplatePlugin.js +162 -162
- package/lib/JsonpTemplatePlugin.js +17 -17
- package/lib/LibManifestPlugin.js +49 -49
- package/lib/LibraryTemplatePlugin.js +77 -77
- package/lib/LoaderTargetPlugin.js +16 -16
- package/lib/MainTemplate.js +169 -169
- package/lib/MemoryOutputFileSystem.js +5 -5
- package/lib/Module.js +116 -116
- package/lib/ModuleFilenameHelpers.js +157 -157
- package/lib/ModuleNotFoundError.js +17 -17
- package/lib/ModuleParseError.js +26 -26
- package/lib/ModuleParserHelpers.js +21 -21
- package/lib/ModuleReason.js +9 -9
- package/lib/ModuleTemplate.js +23 -23
- package/lib/MovedToPluginWarningPlugin.js +17 -17
- package/lib/MultiCompiler.js +166 -166
- package/lib/MultiEntryPlugin.js +31 -31
- package/lib/MultiModule.js +71 -71
- package/lib/MultiModuleFactory.js +18 -18
- package/lib/NamedModulesPlugin.js +21 -21
- package/lib/NewWatchingPlugin.js +12 -12
- package/lib/NoErrorsPlugin.js +18 -18
- package/lib/NodeStuffPlugin.js +99 -99
- package/lib/NormalModule.js +322 -322
- package/lib/NormalModuleFactory.js +171 -171
- package/lib/NormalModuleReplacementPlugin.js +40 -40
- package/lib/NullFactory.js +10 -10
- package/lib/OldWatchingPlugin.js +14 -14
- package/lib/OptionsApply.js +10 -10
- package/lib/OriginalSource.js +5 -5
- package/lib/Parser.js +938 -938
- package/lib/PrefetchPlugin.js +25 -25
- package/lib/ProgressPlugin.js +80 -80
- package/lib/ProvidePlugin.js +48 -48
- package/lib/RawModule.js +65 -65
- package/lib/RawSource.js +5 -5
- package/lib/RecordIdsPlugin.js +130 -130
- package/lib/RequestShortener.js +56 -56
- package/lib/RequireJsStuffPlugin.js +38 -38
- package/lib/ResolverPlugin.js +34 -34
- package/lib/SetVarMainTemplatePlugin.js +36 -36
- package/lib/SingleEntryPlugin.js +24 -24
- package/lib/Source.js +5 -5
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +33 -33
- package/lib/SourceMapDevToolPlugin.js +168 -168
- package/lib/SourceMapSource.js +5 -5
- package/lib/Stats.js +732 -732
- package/lib/Template.js +119 -119
- package/lib/TemplatedPathPlugin.js +111 -111
- package/lib/UmdMainTemplatePlugin.js +146 -146
- package/lib/UnsupportedFeatureWarning.js +14 -14
- package/lib/WarnCaseSensitiveModulesPlugin.js +27 -27
- package/lib/WatchIgnorePlugin.js +45 -45
- package/lib/WebpackOptionsApply.js +376 -376
- package/lib/WebpackOptionsDefaulter.js +112 -112
- package/lib/dependencies/AMDDefineDependency.js +63 -63
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +240 -240
- package/lib/dependencies/AMDPlugin.js +115 -115
- package/lib/dependencies/AMDRequireArrayDependency.js +34 -34
- package/lib/dependencies/AMDRequireContextDependency.js +18 -18
- package/lib/dependencies/AMDRequireDependenciesBlock.js +25 -25
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +145 -145
- package/lib/dependencies/AMDRequireDependency.js +64 -64
- package/lib/dependencies/AMDRequireItemDependency.js +17 -17
- package/lib/dependencies/CommonJsPlugin.js +93 -93
- package/lib/dependencies/CommonJsRequireContextDependency.js +18 -18
- package/lib/dependencies/CommonJsRequireDependency.js +17 -17
- package/lib/dependencies/CommonJsRequireDependencyParserPlugin.js +91 -91
- package/lib/dependencies/ConstDependency.js +29 -29
- package/lib/dependencies/ContextDependency.js +24 -24
- package/lib/dependencies/ContextDependencyHelpers.js +34 -34
- package/lib/dependencies/ContextDependencyTemplateAsId.js +22 -22
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +31 -31
- package/lib/dependencies/ContextElementDependency.js +17 -17
- package/lib/dependencies/DelegatedSourceDependency.js +14 -14
- package/lib/dependencies/DepBlockHelpers.js +41 -41
- package/lib/dependencies/DllEntryDependency.js +17 -17
- package/lib/dependencies/LabeledExportsDependency.js +21 -21
- package/lib/dependencies/LabeledModuleDependency.js +36 -36
- package/lib/dependencies/LabeledModuleDependencyParserPlugin.js +76 -76
- package/lib/dependencies/LabeledModulesPlugin.js +26 -26
- package/lib/dependencies/LoaderDependency.js +14 -14
- package/lib/dependencies/LoaderPlugin.js +61 -61
- package/lib/dependencies/LocalModule.js +19 -19
- package/lib/dependencies/LocalModuleDependency.js +23 -23
- package/lib/dependencies/LocalModulesHelpers.js +43 -43
- package/lib/dependencies/ModuleDependency.js +20 -20
- package/lib/dependencies/ModuleDependencyTemplateAsId.js +22 -22
- package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +22 -22
- package/lib/dependencies/ModuleHotAcceptDependency.js +18 -18
- package/lib/dependencies/ModuleHotDeclineDependency.js +18 -18
- package/lib/dependencies/MultiEntryDependency.js +16 -16
- package/lib/dependencies/NullDependency.js +17 -17
- package/lib/dependencies/NullDependencyTemplate.js +8 -8
- package/lib/dependencies/PrefetchDependency.js +14 -14
- package/lib/dependencies/RequireContextDependency.js +17 -17
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +33 -33
- package/lib/dependencies/RequireContextPlugin.js +64 -64
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +20 -20
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +66 -66
- package/lib/dependencies/RequireEnsureDependency.js +29 -29
- package/lib/dependencies/RequireEnsureItemDependency.js +16 -16
- package/lib/dependencies/RequireEnsurePlugin.js +38 -38
- package/lib/dependencies/RequireHeaderDependency.js +25 -25
- package/lib/dependencies/RequireIncludeDependency.js +25 -25
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +18 -18
- package/lib/dependencies/RequireIncludePlugin.js +31 -31
- package/lib/dependencies/RequireResolveContextDependency.js +18 -18
- package/lib/dependencies/RequireResolveDependency.js +17 -17
- package/lib/dependencies/RequireResolveDependencyParserPlugin.js +69 -69
- package/lib/dependencies/RequireResolveHeaderDependency.js +25 -25
- package/lib/dependencies/SingleEntryDependency.js +14 -14
- package/lib/dependencies/TemplateArgumentDependency.js +26 -26
- package/lib/dependencies/WebpackMissingModule.js +23 -23
- package/lib/dependencies/getFunctionExpression.js +43 -43
- package/lib/node/NodeChunkTemplatePlugin.js +22 -22
- package/lib/node/NodeEnvironmentPlugin.js +25 -25
- package/lib/node/NodeHotUpdateChunkTemplatePlugin.js +24 -24
- package/lib/node/NodeMainTemplate.runtime.js +20 -20
- package/lib/node/NodeMainTemplateAsync.runtime.js +34 -34
- package/lib/node/NodeMainTemplatePlugin.js +164 -164
- package/lib/node/NodeOutputFileSystem.js +17 -17
- package/lib/node/NodeSourcePlugin.js +85 -75
- package/lib/node/NodeTargetPlugin.js +12 -12
- package/lib/node/NodeTemplatePlugin.js +21 -21
- package/lib/node/NodeWatchFileSystem.js +65 -65
- package/lib/node/OldNodeWatchFileSystem.js +265 -265
- package/lib/optimize/AggressiveMergingPlugin.js +115 -115
- package/lib/optimize/CommonsChunkPlugin.js +178 -178
- package/lib/optimize/DedupePlugin.js +227 -227
- package/lib/optimize/FlagIncludedChunksPlugin.js +24 -24
- package/lib/optimize/LimitChunkCountPlugin.js +55 -55
- package/lib/optimize/MergeDuplicateChunksPlugin.js +30 -30
- package/lib/optimize/MinChunkSizePlugin.js +61 -61
- package/lib/optimize/OccurenceOrderPlugin.js +5 -5
- package/lib/optimize/OccurrenceOrderPlugin.js +91 -91
- package/lib/optimize/RemoveEmptyChunksPlugin.js +19 -19
- package/lib/optimize/RemoveParentModulesPlugin.js +50 -50
- package/lib/optimize/UglifyJsPlugin.js +146 -146
- package/lib/removeAndDo.js +13 -13
- package/lib/web/WebEnvironmentPlugin.js +16 -16
- package/lib/webpack.js +113 -113
- package/lib/webpack.web.js +27 -27
- package/lib/webworker/WebWorkerChunkTemplatePlugin.js +26 -26
- package/lib/webworker/WebWorkerMainTemplatePlugin.js +78 -78
- package/lib/webworker/WebWorkerTemplatePlugin.js +15 -15
- package/package.json +4 -4
@@ -1,115 +1,115 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
function AggressiveMergingPlugin(options) {
|
6
|
-
if(options !== undefined && typeof options !== "object" || Array.isArray(options)) {
|
7
|
-
throw new Error("Argument should be an options object. To use defaults, pass in nothing.\nFor more info on options, see https://webpack.github.io/docs/list-of-plugins.html");
|
8
|
-
}
|
9
|
-
this.options = options || {};
|
10
|
-
}
|
11
|
-
module.exports = AggressiveMergingPlugin;
|
12
|
-
|
13
|
-
AggressiveMergingPlugin.prototype.apply = function(compiler) {
|
14
|
-
var options = this.options;
|
15
|
-
var minSizeReduce = options.minSizeReduce || 1.5;
|
16
|
-
|
17
|
-
function getParentsWeight(chunk) {
|
18
|
-
return chunk.parents.map(function(p) {
|
19
|
-
return p.initial ? options.entryChunkMultiplicator || 10 : 1;
|
20
|
-
}).reduce(function(a, b) {
|
21
|
-
return a + b;
|
22
|
-
}, 0);
|
23
|
-
}
|
24
|
-
compiler.plugin("compilation", function(compilation) {
|
25
|
-
compilation.plugin("optimize-chunks", function(chunks) {
|
26
|
-
var combinations = [];
|
27
|
-
chunks.forEach(function(a, idx) {
|
28
|
-
if(a.initial) return;
|
29
|
-
for(var i = 0; i < idx; i++) {
|
30
|
-
var b = chunks[i];
|
31
|
-
if(b.initial) continue;
|
32
|
-
combinations.push([b, a]);
|
33
|
-
}
|
34
|
-
});
|
35
|
-
|
36
|
-
combinations.forEach(function(pair) {
|
37
|
-
var a = pair[0].size({
|
38
|
-
chunkOverhead: 0
|
39
|
-
});
|
40
|
-
var b = pair[1].size({
|
41
|
-
chunkOverhead: 0
|
42
|
-
});
|
43
|
-
var ab = pair[0].integratedSize(pair[1], {
|
44
|
-
chunkOverhead: 0
|
45
|
-
});
|
46
|
-
pair.push({
|
47
|
-
a: a,
|
48
|
-
b: b,
|
49
|
-
ab: ab
|
50
|
-
});
|
51
|
-
if(ab === false) {
|
52
|
-
pair.unshift(false);
|
53
|
-
} else if(options.moveToParents) {
|
54
|
-
var aOnly = ab - b;
|
55
|
-
var bOnly = ab - a;
|
56
|
-
var common = a + b - ab;
|
57
|
-
var newSize = common + getParentsWeight(pair[0]) * aOnly + getParentsWeight(pair[1]) * bOnly;
|
58
|
-
pair.push({
|
59
|
-
aOnly: aOnly,
|
60
|
-
bOnly: bOnly,
|
61
|
-
common: common,
|
62
|
-
newSize: newSize
|
63
|
-
});
|
64
|
-
} else {
|
65
|
-
var newSize = ab;
|
66
|
-
}
|
67
|
-
|
68
|
-
pair.unshift((a + b) / newSize);
|
69
|
-
});
|
70
|
-
combinations = combinations.filter(function(pair) {
|
71
|
-
return pair[0] !== false;
|
72
|
-
});
|
73
|
-
combinations.sort(function(a, b) {
|
74
|
-
return b[0] - a[0];
|
75
|
-
});
|
76
|
-
|
77
|
-
var pair = combinations[0];
|
78
|
-
|
79
|
-
if(!pair) return;
|
80
|
-
if(pair[0] < minSizeReduce) return;
|
81
|
-
|
82
|
-
if(options.moveToParents) {
|
83
|
-
var commonModules = pair[1].modules.filter(function(m) {
|
84
|
-
return pair[2].modules.indexOf(m) >= 0;
|
85
|
-
});
|
86
|
-
var aOnlyModules = pair[1].modules.filter(function(m) {
|
87
|
-
return commonModules.indexOf(m) < 0;
|
88
|
-
});
|
89
|
-
var bOnlyModules = pair[2].modules.filter(function(m) {
|
90
|
-
return commonModules.indexOf(m) < 0;
|
91
|
-
});
|
92
|
-
aOnlyModules.forEach(function(m) {
|
93
|
-
pair[1].removeModule(m);
|
94
|
-
m.removeChunk(pair[1]);
|
95
|
-
pair[1].parents.forEach(function(c) {
|
96
|
-
c.addModule(m);
|
97
|
-
m.addChunk(c);
|
98
|
-
});
|
99
|
-
});
|
100
|
-
bOnlyModules.forEach(function(m) {
|
101
|
-
pair[2].removeModule(m);
|
102
|
-
m.removeChunk(pair[2]);
|
103
|
-
pair[2].parents.forEach(function(c) {
|
104
|
-
c.addModule(m);
|
105
|
-
m.addChunk(c);
|
106
|
-
});
|
107
|
-
});
|
108
|
-
}
|
109
|
-
if(pair[1].integrate(pair[2], "aggressive-merge")) {
|
110
|
-
chunks.splice(chunks.indexOf(pair[2]), 1);
|
111
|
-
this.restartApplyPlugins();
|
112
|
-
}
|
113
|
-
});
|
114
|
-
});
|
115
|
-
};
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
function AggressiveMergingPlugin(options) {
|
6
|
+
if(options !== undefined && typeof options !== "object" || Array.isArray(options)) {
|
7
|
+
throw new Error("Argument should be an options object. To use defaults, pass in nothing.\nFor more info on options, see https://webpack.github.io/docs/list-of-plugins.html");
|
8
|
+
}
|
9
|
+
this.options = options || {};
|
10
|
+
}
|
11
|
+
module.exports = AggressiveMergingPlugin;
|
12
|
+
|
13
|
+
AggressiveMergingPlugin.prototype.apply = function(compiler) {
|
14
|
+
var options = this.options;
|
15
|
+
var minSizeReduce = options.minSizeReduce || 1.5;
|
16
|
+
|
17
|
+
function getParentsWeight(chunk) {
|
18
|
+
return chunk.parents.map(function(p) {
|
19
|
+
return p.initial ? options.entryChunkMultiplicator || 10 : 1;
|
20
|
+
}).reduce(function(a, b) {
|
21
|
+
return a + b;
|
22
|
+
}, 0);
|
23
|
+
}
|
24
|
+
compiler.plugin("compilation", function(compilation) {
|
25
|
+
compilation.plugin("optimize-chunks", function(chunks) {
|
26
|
+
var combinations = [];
|
27
|
+
chunks.forEach(function(a, idx) {
|
28
|
+
if(a.initial) return;
|
29
|
+
for(var i = 0; i < idx; i++) {
|
30
|
+
var b = chunks[i];
|
31
|
+
if(b.initial) continue;
|
32
|
+
combinations.push([b, a]);
|
33
|
+
}
|
34
|
+
});
|
35
|
+
|
36
|
+
combinations.forEach(function(pair) {
|
37
|
+
var a = pair[0].size({
|
38
|
+
chunkOverhead: 0
|
39
|
+
});
|
40
|
+
var b = pair[1].size({
|
41
|
+
chunkOverhead: 0
|
42
|
+
});
|
43
|
+
var ab = pair[0].integratedSize(pair[1], {
|
44
|
+
chunkOverhead: 0
|
45
|
+
});
|
46
|
+
pair.push({
|
47
|
+
a: a,
|
48
|
+
b: b,
|
49
|
+
ab: ab
|
50
|
+
});
|
51
|
+
if(ab === false) {
|
52
|
+
pair.unshift(false);
|
53
|
+
} else if(options.moveToParents) {
|
54
|
+
var aOnly = ab - b;
|
55
|
+
var bOnly = ab - a;
|
56
|
+
var common = a + b - ab;
|
57
|
+
var newSize = common + getParentsWeight(pair[0]) * aOnly + getParentsWeight(pair[1]) * bOnly;
|
58
|
+
pair.push({
|
59
|
+
aOnly: aOnly,
|
60
|
+
bOnly: bOnly,
|
61
|
+
common: common,
|
62
|
+
newSize: newSize
|
63
|
+
});
|
64
|
+
} else {
|
65
|
+
var newSize = ab;
|
66
|
+
}
|
67
|
+
|
68
|
+
pair.unshift((a + b) / newSize);
|
69
|
+
});
|
70
|
+
combinations = combinations.filter(function(pair) {
|
71
|
+
return pair[0] !== false;
|
72
|
+
});
|
73
|
+
combinations.sort(function(a, b) {
|
74
|
+
return b[0] - a[0];
|
75
|
+
});
|
76
|
+
|
77
|
+
var pair = combinations[0];
|
78
|
+
|
79
|
+
if(!pair) return;
|
80
|
+
if(pair[0] < minSizeReduce) return;
|
81
|
+
|
82
|
+
if(options.moveToParents) {
|
83
|
+
var commonModules = pair[1].modules.filter(function(m) {
|
84
|
+
return pair[2].modules.indexOf(m) >= 0;
|
85
|
+
});
|
86
|
+
var aOnlyModules = pair[1].modules.filter(function(m) {
|
87
|
+
return commonModules.indexOf(m) < 0;
|
88
|
+
});
|
89
|
+
var bOnlyModules = pair[2].modules.filter(function(m) {
|
90
|
+
return commonModules.indexOf(m) < 0;
|
91
|
+
});
|
92
|
+
aOnlyModules.forEach(function(m) {
|
93
|
+
pair[1].removeModule(m);
|
94
|
+
m.removeChunk(pair[1]);
|
95
|
+
pair[1].parents.forEach(function(c) {
|
96
|
+
c.addModule(m);
|
97
|
+
m.addChunk(c);
|
98
|
+
});
|
99
|
+
});
|
100
|
+
bOnlyModules.forEach(function(m) {
|
101
|
+
pair[2].removeModule(m);
|
102
|
+
m.removeChunk(pair[2]);
|
103
|
+
pair[2].parents.forEach(function(c) {
|
104
|
+
c.addModule(m);
|
105
|
+
m.addChunk(c);
|
106
|
+
});
|
107
|
+
});
|
108
|
+
}
|
109
|
+
if(pair[1].integrate(pair[2], "aggressive-merge")) {
|
110
|
+
chunks.splice(chunks.indexOf(pair[2]), 1);
|
111
|
+
this.restartApplyPlugins();
|
112
|
+
}
|
113
|
+
});
|
114
|
+
});
|
115
|
+
};
|
@@ -1,178 +1,178 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
var nextIdent = 0;
|
6
|
-
|
7
|
-
function CommonsChunkPlugin(options, filenameTemplate, selectedChunks, minChunks) {
|
8
|
-
if(options && typeof options === "object" && !Array.isArray(options)) {
|
9
|
-
this.chunkNames = options.name || options.names;
|
10
|
-
this.filenameTemplate = options.filename;
|
11
|
-
this.minChunks = options.minChunks;
|
12
|
-
this.selectedChunks = options.chunks;
|
13
|
-
if(options.children) this.selectedChunks = false;
|
14
|
-
this.async = options.async;
|
15
|
-
this.minSize = options.minSize;
|
16
|
-
} else {
|
17
|
-
var chunkNames = options;
|
18
|
-
if(typeof filenameTemplate !== "string" && filenameTemplate !== null) {
|
19
|
-
minChunks = selectedChunks;
|
20
|
-
selectedChunks = filenameTemplate;
|
21
|
-
filenameTemplate = chunkNames;
|
22
|
-
}
|
23
|
-
if(!Array.isArray(selectedChunks) && typeof selectedChunks !== "boolean" && selectedChunks !== null) {
|
24
|
-
minChunks = selectedChunks;
|
25
|
-
selectedChunks = undefined;
|
26
|
-
}
|
27
|
-
this.chunkNames = chunkNames;
|
28
|
-
this.filenameTemplate = filenameTemplate;
|
29
|
-
this.minChunks = minChunks;
|
30
|
-
this.selectedChunks = selectedChunks;
|
31
|
-
}
|
32
|
-
this.ident = __filename + (nextIdent++);
|
33
|
-
}
|
34
|
-
|
35
|
-
module.exports = CommonsChunkPlugin;
|
36
|
-
CommonsChunkPlugin.prototype.apply = function(compiler) {
|
37
|
-
var chunkNames = this.chunkNames;
|
38
|
-
var filenameTemplate = this.filenameTemplate;
|
39
|
-
var minChunks = this.minChunks;
|
40
|
-
var selectedChunks = this.selectedChunks;
|
41
|
-
var async = this.async;
|
42
|
-
var minSize = this.minSize;
|
43
|
-
var ident = this.ident;
|
44
|
-
compiler.plugin("this-compilation", function(compilation) {
|
45
|
-
compilation.plugin(["optimize-chunks", "optimize-extracted-chunks"], function(chunks) {
|
46
|
-
// only optimize once
|
47
|
-
if(compilation[ident]) return;
|
48
|
-
compilation[ident] = true;
|
49
|
-
|
50
|
-
var commonChunks;
|
51
|
-
if(!chunkNames && (selectedChunks === false || async)) {
|
52
|
-
commonChunks = chunks;
|
53
|
-
} else if(Array.isArray(chunkNames) || typeof chunkNames === "string") {
|
54
|
-
commonChunks = [].concat(chunkNames).map(function(chunkName) {
|
55
|
-
var chunk = chunks.filter(function(chunk) {
|
56
|
-
return chunk.name === chunkName;
|
57
|
-
})[0];
|
58
|
-
if(!chunk) {
|
59
|
-
chunk = this.addChunk(chunkName);
|
60
|
-
chunk.initial = chunk.entry = true;
|
61
|
-
}
|
62
|
-
return chunk;
|
63
|
-
}, this);
|
64
|
-
} else {
|
65
|
-
throw new Error("Invalid chunkNames argument");
|
66
|
-
}
|
67
|
-
commonChunks.forEach(function processCommonChunk(commonChunk, idx) {
|
68
|
-
var commonModulesCount = [];
|
69
|
-
var commonModules = [];
|
70
|
-
var usedChunks;
|
71
|
-
if(Array.isArray(selectedChunks)) {
|
72
|
-
usedChunks = chunks.filter(function(chunk) {
|
73
|
-
if(chunk === commonChunk) return false;
|
74
|
-
return selectedChunks.indexOf(chunk.name) >= 0;
|
75
|
-
});
|
76
|
-
} else if(selectedChunks === false || async) {
|
77
|
-
usedChunks = (commonChunk.chunks || []).filter(function(chunk) {
|
78
|
-
// we can only move modules from this chunk if the "commonChunk" is the only parent
|
79
|
-
return async || chunk.parents.length === 1;
|
80
|
-
});
|
81
|
-
} else {
|
82
|
-
if(!commonChunk.entry) {
|
83
|
-
compilation.errors.push(new Error("CommonsChunkPlugin: While running in normal mode it's not allowed to use a non-entry chunk (" + commonChunk.name + ")"));
|
84
|
-
return;
|
85
|
-
}
|
86
|
-
usedChunks = chunks.filter(function(chunk) {
|
87
|
-
var found = commonChunks.indexOf(chunk);
|
88
|
-
if(found >= idx) return false;
|
89
|
-
return chunk.entry;
|
90
|
-
});
|
91
|
-
}
|
92
|
-
if(async) {
|
93
|
-
var asyncChunk = this.addChunk(typeof async === "string" ? async : undefined);
|
94
|
-
asyncChunk.chunkReason = "async commons chunk";
|
95
|
-
asyncChunk.extraAsync = true;
|
96
|
-
asyncChunk.addParent(commonChunk);
|
97
|
-
commonChunk.addChunk(asyncChunk);
|
98
|
-
commonChunk = asyncChunk;
|
99
|
-
}
|
100
|
-
usedChunks.forEach(function(chunk) {
|
101
|
-
chunk.modules.forEach(function(module) {
|
102
|
-
var idx = commonModules.indexOf(module);
|
103
|
-
if(idx < 0) {
|
104
|
-
commonModules.push(module);
|
105
|
-
commonModulesCount.push(1);
|
106
|
-
} else {
|
107
|
-
commonModulesCount[idx]++;
|
108
|
-
}
|
109
|
-
});
|
110
|
-
});
|
111
|
-
var reallyUsedChunks = [];
|
112
|
-
var reallyUsedModules = [];
|
113
|
-
commonModulesCount.forEach(function(count, idx) {
|
114
|
-
var module = commonModules[idx];
|
115
|
-
if(typeof minChunks === "function") {
|
116
|
-
if(!minChunks(module, count))
|
117
|
-
return;
|
118
|
-
} else if(count < (minChunks || Math.max(2, usedChunks.length))) {
|
119
|
-
return;
|
120
|
-
}
|
121
|
-
reallyUsedModules.push(module);
|
122
|
-
});
|
123
|
-
if(minSize) {
|
124
|
-
var size = reallyUsedModules.reduce(function(a, b) {
|
125
|
-
return a + b.size();
|
126
|
-
}, 0);
|
127
|
-
if(size < minSize)
|
128
|
-
return;
|
129
|
-
}
|
130
|
-
reallyUsedModules.forEach(function(module) {
|
131
|
-
usedChunks.forEach(function(chunk) {
|
132
|
-
if(module.removeChunk(chunk)) {
|
133
|
-
if(reallyUsedChunks.indexOf(chunk) < 0)
|
134
|
-
reallyUsedChunks.push(chunk);
|
135
|
-
}
|
136
|
-
});
|
137
|
-
commonChunk.addModule(module);
|
138
|
-
module.addChunk(commonChunk);
|
139
|
-
});
|
140
|
-
if(async) {
|
141
|
-
reallyUsedChunks.forEach(function(chunk) {
|
142
|
-
if(chunk.initial || chunk.entry)
|
143
|
-
return;
|
144
|
-
chunk.blocks.forEach(function(block) {
|
145
|
-
block.chunks.unshift(commonChunk);
|
146
|
-
commonChunk.addBlock(block);
|
147
|
-
});
|
148
|
-
});
|
149
|
-
asyncChunk.origins = reallyUsedChunks.map(function(chunk) {
|
150
|
-
return chunk.origins.map(function(origin) {
|
151
|
-
var newOrigin = Object.create(origin);
|
152
|
-
newOrigin.reasons = (origin.reasons || []).slice();
|
153
|
-
newOrigin.reasons.push("async commons");
|
154
|
-
return newOrigin;
|
155
|
-
});
|
156
|
-
}).reduce(function(arr, a) {
|
157
|
-
arr.push.apply(arr, a);
|
158
|
-
return arr;
|
159
|
-
}, []);
|
160
|
-
} else {
|
161
|
-
usedChunks.forEach(function(chunk) {
|
162
|
-
chunk.parents = [commonChunk];
|
163
|
-
commonChunk.chunks.push(chunk);
|
164
|
-
if(chunk.initial)
|
165
|
-
commonChunk.initial = true;
|
166
|
-
if(chunk.entry) {
|
167
|
-
commonChunk.entry = true;
|
168
|
-
chunk.entry = false;
|
169
|
-
}
|
170
|
-
});
|
171
|
-
}
|
172
|
-
if(filenameTemplate)
|
173
|
-
commonChunk.filenameTemplate = filenameTemplate;
|
174
|
-
}, this);
|
175
|
-
this.restartApplyPlugins();
|
176
|
-
});
|
177
|
-
});
|
178
|
-
};
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
var nextIdent = 0;
|
6
|
+
|
7
|
+
function CommonsChunkPlugin(options, filenameTemplate, selectedChunks, minChunks) {
|
8
|
+
if(options && typeof options === "object" && !Array.isArray(options)) {
|
9
|
+
this.chunkNames = options.name || options.names;
|
10
|
+
this.filenameTemplate = options.filename;
|
11
|
+
this.minChunks = options.minChunks;
|
12
|
+
this.selectedChunks = options.chunks;
|
13
|
+
if(options.children) this.selectedChunks = false;
|
14
|
+
this.async = options.async;
|
15
|
+
this.minSize = options.minSize;
|
16
|
+
} else {
|
17
|
+
var chunkNames = options;
|
18
|
+
if(typeof filenameTemplate !== "string" && filenameTemplate !== null) {
|
19
|
+
minChunks = selectedChunks;
|
20
|
+
selectedChunks = filenameTemplate;
|
21
|
+
filenameTemplate = chunkNames;
|
22
|
+
}
|
23
|
+
if(!Array.isArray(selectedChunks) && typeof selectedChunks !== "boolean" && selectedChunks !== null) {
|
24
|
+
minChunks = selectedChunks;
|
25
|
+
selectedChunks = undefined;
|
26
|
+
}
|
27
|
+
this.chunkNames = chunkNames;
|
28
|
+
this.filenameTemplate = filenameTemplate;
|
29
|
+
this.minChunks = minChunks;
|
30
|
+
this.selectedChunks = selectedChunks;
|
31
|
+
}
|
32
|
+
this.ident = __filename + (nextIdent++);
|
33
|
+
}
|
34
|
+
|
35
|
+
module.exports = CommonsChunkPlugin;
|
36
|
+
CommonsChunkPlugin.prototype.apply = function(compiler) {
|
37
|
+
var chunkNames = this.chunkNames;
|
38
|
+
var filenameTemplate = this.filenameTemplate;
|
39
|
+
var minChunks = this.minChunks;
|
40
|
+
var selectedChunks = this.selectedChunks;
|
41
|
+
var async = this.async;
|
42
|
+
var minSize = this.minSize;
|
43
|
+
var ident = this.ident;
|
44
|
+
compiler.plugin("this-compilation", function(compilation) {
|
45
|
+
compilation.plugin(["optimize-chunks", "optimize-extracted-chunks"], function(chunks) {
|
46
|
+
// only optimize once
|
47
|
+
if(compilation[ident]) return;
|
48
|
+
compilation[ident] = true;
|
49
|
+
|
50
|
+
var commonChunks;
|
51
|
+
if(!chunkNames && (selectedChunks === false || async)) {
|
52
|
+
commonChunks = chunks;
|
53
|
+
} else if(Array.isArray(chunkNames) || typeof chunkNames === "string") {
|
54
|
+
commonChunks = [].concat(chunkNames).map(function(chunkName) {
|
55
|
+
var chunk = chunks.filter(function(chunk) {
|
56
|
+
return chunk.name === chunkName;
|
57
|
+
})[0];
|
58
|
+
if(!chunk) {
|
59
|
+
chunk = this.addChunk(chunkName);
|
60
|
+
chunk.initial = chunk.entry = true;
|
61
|
+
}
|
62
|
+
return chunk;
|
63
|
+
}, this);
|
64
|
+
} else {
|
65
|
+
throw new Error("Invalid chunkNames argument");
|
66
|
+
}
|
67
|
+
commonChunks.forEach(function processCommonChunk(commonChunk, idx) {
|
68
|
+
var commonModulesCount = [];
|
69
|
+
var commonModules = [];
|
70
|
+
var usedChunks;
|
71
|
+
if(Array.isArray(selectedChunks)) {
|
72
|
+
usedChunks = chunks.filter(function(chunk) {
|
73
|
+
if(chunk === commonChunk) return false;
|
74
|
+
return selectedChunks.indexOf(chunk.name) >= 0;
|
75
|
+
});
|
76
|
+
} else if(selectedChunks === false || async) {
|
77
|
+
usedChunks = (commonChunk.chunks || []).filter(function(chunk) {
|
78
|
+
// we can only move modules from this chunk if the "commonChunk" is the only parent
|
79
|
+
return async || chunk.parents.length === 1;
|
80
|
+
});
|
81
|
+
} else {
|
82
|
+
if(!commonChunk.entry) {
|
83
|
+
compilation.errors.push(new Error("CommonsChunkPlugin: While running in normal mode it's not allowed to use a non-entry chunk (" + commonChunk.name + ")"));
|
84
|
+
return;
|
85
|
+
}
|
86
|
+
usedChunks = chunks.filter(function(chunk) {
|
87
|
+
var found = commonChunks.indexOf(chunk);
|
88
|
+
if(found >= idx) return false;
|
89
|
+
return chunk.entry;
|
90
|
+
});
|
91
|
+
}
|
92
|
+
if(async) {
|
93
|
+
var asyncChunk = this.addChunk(typeof async === "string" ? async : undefined);
|
94
|
+
asyncChunk.chunkReason = "async commons chunk";
|
95
|
+
asyncChunk.extraAsync = true;
|
96
|
+
asyncChunk.addParent(commonChunk);
|
97
|
+
commonChunk.addChunk(asyncChunk);
|
98
|
+
commonChunk = asyncChunk;
|
99
|
+
}
|
100
|
+
usedChunks.forEach(function(chunk) {
|
101
|
+
chunk.modules.forEach(function(module) {
|
102
|
+
var idx = commonModules.indexOf(module);
|
103
|
+
if(idx < 0) {
|
104
|
+
commonModules.push(module);
|
105
|
+
commonModulesCount.push(1);
|
106
|
+
} else {
|
107
|
+
commonModulesCount[idx]++;
|
108
|
+
}
|
109
|
+
});
|
110
|
+
});
|
111
|
+
var reallyUsedChunks = [];
|
112
|
+
var reallyUsedModules = [];
|
113
|
+
commonModulesCount.forEach(function(count, idx) {
|
114
|
+
var module = commonModules[idx];
|
115
|
+
if(typeof minChunks === "function") {
|
116
|
+
if(!minChunks(module, count))
|
117
|
+
return;
|
118
|
+
} else if(count < (minChunks || Math.max(2, usedChunks.length))) {
|
119
|
+
return;
|
120
|
+
}
|
121
|
+
reallyUsedModules.push(module);
|
122
|
+
});
|
123
|
+
if(minSize) {
|
124
|
+
var size = reallyUsedModules.reduce(function(a, b) {
|
125
|
+
return a + b.size();
|
126
|
+
}, 0);
|
127
|
+
if(size < minSize)
|
128
|
+
return;
|
129
|
+
}
|
130
|
+
reallyUsedModules.forEach(function(module) {
|
131
|
+
usedChunks.forEach(function(chunk) {
|
132
|
+
if(module.removeChunk(chunk)) {
|
133
|
+
if(reallyUsedChunks.indexOf(chunk) < 0)
|
134
|
+
reallyUsedChunks.push(chunk);
|
135
|
+
}
|
136
|
+
});
|
137
|
+
commonChunk.addModule(module);
|
138
|
+
module.addChunk(commonChunk);
|
139
|
+
});
|
140
|
+
if(async) {
|
141
|
+
reallyUsedChunks.forEach(function(chunk) {
|
142
|
+
if(chunk.initial || chunk.entry)
|
143
|
+
return;
|
144
|
+
chunk.blocks.forEach(function(block) {
|
145
|
+
block.chunks.unshift(commonChunk);
|
146
|
+
commonChunk.addBlock(block);
|
147
|
+
});
|
148
|
+
});
|
149
|
+
asyncChunk.origins = reallyUsedChunks.map(function(chunk) {
|
150
|
+
return chunk.origins.map(function(origin) {
|
151
|
+
var newOrigin = Object.create(origin);
|
152
|
+
newOrigin.reasons = (origin.reasons || []).slice();
|
153
|
+
newOrigin.reasons.push("async commons");
|
154
|
+
return newOrigin;
|
155
|
+
});
|
156
|
+
}).reduce(function(arr, a) {
|
157
|
+
arr.push.apply(arr, a);
|
158
|
+
return arr;
|
159
|
+
}, []);
|
160
|
+
} else {
|
161
|
+
usedChunks.forEach(function(chunk) {
|
162
|
+
chunk.parents = [commonChunk];
|
163
|
+
commonChunk.chunks.push(chunk);
|
164
|
+
if(chunk.initial)
|
165
|
+
commonChunk.initial = true;
|
166
|
+
if(chunk.entry) {
|
167
|
+
commonChunk.entry = true;
|
168
|
+
chunk.entry = false;
|
169
|
+
}
|
170
|
+
});
|
171
|
+
}
|
172
|
+
if(filenameTemplate)
|
173
|
+
commonChunk.filenameTemplate = filenameTemplate;
|
174
|
+
}, this);
|
175
|
+
this.restartApplyPlugins();
|
176
|
+
});
|
177
|
+
});
|
178
|
+
};
|