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
package/lib/Chunk.js
CHANGED
@@ -1,252 +1,252 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
function Chunk(name, module, loc) {
|
6
|
-
this.id = null;
|
7
|
-
this.ids = null;
|
8
|
-
this.name = name;
|
9
|
-
this.modules = [];
|
10
|
-
this.chunks = [];
|
11
|
-
this.parents = [];
|
12
|
-
this.blocks = [];
|
13
|
-
this.origins = [];
|
14
|
-
this.files = [];
|
15
|
-
this.rendered = false;
|
16
|
-
this.entry = false;
|
17
|
-
this.initial = false;
|
18
|
-
if(module) {
|
19
|
-
this.origins.push({
|
20
|
-
module: module,
|
21
|
-
loc: loc,
|
22
|
-
name: name
|
23
|
-
});
|
24
|
-
}
|
25
|
-
}
|
26
|
-
module.exports = Chunk;
|
27
|
-
|
28
|
-
Chunk.prototype.addModule = function(module) {
|
29
|
-
if(this.modules.indexOf(module) >= 0) {
|
30
|
-
return false;
|
31
|
-
}
|
32
|
-
this.modules.push(module);
|
33
|
-
return true;
|
34
|
-
};
|
35
|
-
|
36
|
-
Chunk.prototype._removeAndDo = require("./removeAndDo");
|
37
|
-
|
38
|
-
Chunk.prototype.removeModule = function(module) {
|
39
|
-
this._removeAndDo("modules", module, "removeChunk");
|
40
|
-
};
|
41
|
-
|
42
|
-
Chunk.prototype.removeChunk = function(chunk) {
|
43
|
-
this._removeAndDo("chunks", chunk, "removeParent");
|
44
|
-
};
|
45
|
-
|
46
|
-
Chunk.prototype.removeParent = function(chunk) {
|
47
|
-
this._removeAndDo("parents", chunk, "removeChunk");
|
48
|
-
};
|
49
|
-
|
50
|
-
function createAdder(collection) {
|
51
|
-
return function(chunk) {
|
52
|
-
if(chunk === this) {
|
53
|
-
return false;
|
54
|
-
}
|
55
|
-
if(this[collection].indexOf(chunk) >= 0) {
|
56
|
-
return false;
|
57
|
-
}
|
58
|
-
this[collection].push(chunk);
|
59
|
-
return true;
|
60
|
-
};
|
61
|
-
}
|
62
|
-
|
63
|
-
Chunk.prototype.addChunk = createAdder("chunks");
|
64
|
-
|
65
|
-
Chunk.prototype.addParent = createAdder("parents");
|
66
|
-
|
67
|
-
Chunk.prototype.addBlock = function(block) {
|
68
|
-
if(this.blocks.indexOf(block) >= 0) {
|
69
|
-
return false;
|
70
|
-
}
|
71
|
-
this.blocks.push(block);
|
72
|
-
return true;
|
73
|
-
};
|
74
|
-
|
75
|
-
Chunk.prototype.addOrigin = function(module, loc) {
|
76
|
-
this.origins.push({
|
77
|
-
module: module,
|
78
|
-
loc: loc,
|
79
|
-
name: this.name
|
80
|
-
});
|
81
|
-
};
|
82
|
-
|
83
|
-
Chunk.prototype.remove = function(reason) {
|
84
|
-
this.modules.slice().forEach(function(m) {
|
85
|
-
m.removeChunk(this);
|
86
|
-
}, this);
|
87
|
-
this.parents.forEach(function(c) {
|
88
|
-
var idx = c.chunks.indexOf(this);
|
89
|
-
if(idx >= 0) {
|
90
|
-
c.chunks.splice(idx, 1);
|
91
|
-
}
|
92
|
-
this.chunks.forEach(function(cc) {
|
93
|
-
cc.addParent(c);
|
94
|
-
});
|
95
|
-
}, this);
|
96
|
-
this.chunks.forEach(function(c) {
|
97
|
-
var idx = c.parents.indexOf(this);
|
98
|
-
if(idx >= 0) {
|
99
|
-
c.parents.splice(idx, 1);
|
100
|
-
}
|
101
|
-
this.parents.forEach(function(cc) {
|
102
|
-
cc.addChunk(c);
|
103
|
-
});
|
104
|
-
}, this);
|
105
|
-
this.blocks.forEach(function(b) {
|
106
|
-
var idx = b.chunks.indexOf(this);
|
107
|
-
if(idx >= 0) {
|
108
|
-
b.chunks.splice(idx, 1);
|
109
|
-
if(b.chunks.length === 0) {
|
110
|
-
b.chunks = null;
|
111
|
-
b.chunkReason = reason;
|
112
|
-
}
|
113
|
-
}
|
114
|
-
}, this);
|
115
|
-
};
|
116
|
-
|
117
|
-
Chunk.prototype.integrate = function(other, reason) {
|
118
|
-
if(!this.canBeIntegrated(other)) {
|
119
|
-
return false;
|
120
|
-
}
|
121
|
-
|
122
|
-
var otherModules = other.modules.slice();
|
123
|
-
otherModules.forEach(function(m) {
|
124
|
-
m.removeChunk(other);
|
125
|
-
m.addChunk(this);
|
126
|
-
this.addModule(m);
|
127
|
-
m.rewriteChunkInReasons(other, [this]);
|
128
|
-
}, this);
|
129
|
-
other.modules.length = 0;
|
130
|
-
|
131
|
-
function moveChunks(chunks, kind, onChunk) {
|
132
|
-
chunks.forEach(function(c) {
|
133
|
-
var idx = c[kind].indexOf(other);
|
134
|
-
if(idx >= 0) {
|
135
|
-
c[kind].splice(idx, 1);
|
136
|
-
}
|
137
|
-
onChunk(c);
|
138
|
-
});
|
139
|
-
}
|
140
|
-
moveChunks(other.parents, "chunks", function(c) {
|
141
|
-
if(c !== this && this.addParent(c)) {
|
142
|
-
c.addChunk(this);
|
143
|
-
}
|
144
|
-
}.bind(this));
|
145
|
-
other.parents.length = 0;
|
146
|
-
moveChunks(other.chunks, "parents", function(c) {
|
147
|
-
if(c !== this && this.addChunk(c)) {
|
148
|
-
c.addParent(this);
|
149
|
-
}
|
150
|
-
}.bind(this));
|
151
|
-
other.chunks.length = 0;
|
152
|
-
other.blocks.forEach(function(b) {
|
153
|
-
b.chunks = (b.chunks || [this]).map(function(c) {
|
154
|
-
return c === other ? this : c;
|
155
|
-
}, this);
|
156
|
-
b.chunkReason = reason;
|
157
|
-
this.addBlock(b);
|
158
|
-
}, this);
|
159
|
-
other.blocks.length = 0;
|
160
|
-
other.origins.forEach(function(origin) {
|
161
|
-
if(!origin.reasons) {
|
162
|
-
origin.reasons = [reason];
|
163
|
-
} else if(origin.reasons[0] !== reason) {
|
164
|
-
origin.reasons.unshift(reason);
|
165
|
-
}
|
166
|
-
this.origins.push(origin);
|
167
|
-
}, this);
|
168
|
-
return true;
|
169
|
-
};
|
170
|
-
|
171
|
-
Chunk.prototype.isEmpty = function() {
|
172
|
-
return this.modules.length === 0;
|
173
|
-
};
|
174
|
-
|
175
|
-
Chunk.prototype.updateHash = function(hash) {
|
176
|
-
hash.update(this.id + " ");
|
177
|
-
hash.update(this.ids ? this.ids.join(",") : "");
|
178
|
-
hash.update(this.name + "");
|
179
|
-
this.modules.forEach(function(m) {
|
180
|
-
m.updateHash(hash);
|
181
|
-
});
|
182
|
-
};
|
183
|
-
|
184
|
-
Chunk.prototype.size = function(options) {
|
185
|
-
var CHUNK_OVERHEAD = options.chunkOverhead || 10000;
|
186
|
-
var ENTRY_CHUNK_MULTIPLICATOR = options.entryChunkMultiplicator || 10;
|
187
|
-
|
188
|
-
var modulesSize = this.modules.reduce(function(a, b) {
|
189
|
-
return a + b.size();
|
190
|
-
}, 0);
|
191
|
-
return modulesSize * (this.initial ? ENTRY_CHUNK_MULTIPLICATOR : 1) + CHUNK_OVERHEAD;
|
192
|
-
};
|
193
|
-
|
194
|
-
Chunk.prototype.canBeIntegrated = function(other) {
|
195
|
-
if(other.initial) {
|
196
|
-
return false;
|
197
|
-
}
|
198
|
-
if(this.initial) {
|
199
|
-
if(other.parents.length !== 1 || other.parents[0] !== this) {
|
200
|
-
return false;
|
201
|
-
}
|
202
|
-
}
|
203
|
-
return true;
|
204
|
-
};
|
205
|
-
|
206
|
-
Chunk.prototype.integratedSize = function(other, options) {
|
207
|
-
// Chunk if it's possible to integrate this chunk
|
208
|
-
if(!this.canBeIntegrated(other)) {
|
209
|
-
return false;
|
210
|
-
}
|
211
|
-
|
212
|
-
var CHUNK_OVERHEAD = options.chunkOverhead || 10000;
|
213
|
-
var ENTRY_CHUNK_MULTIPLICATOR = options.entryChunkMultiplicator || 10;
|
214
|
-
|
215
|
-
var mergedModules = this.modules.slice();
|
216
|
-
other.modules.forEach(function(m) {
|
217
|
-
if(this.modules.indexOf(m) < 0) {
|
218
|
-
mergedModules.push(m);
|
219
|
-
}
|
220
|
-
}, this);
|
221
|
-
|
222
|
-
var modulesSize = mergedModules.map(function(m) {
|
223
|
-
return m.size();
|
224
|
-
}).reduce(function(a, b) {
|
225
|
-
return a + b;
|
226
|
-
}, 0);
|
227
|
-
return modulesSize * (this.initial || other.initial ? ENTRY_CHUNK_MULTIPLICATOR : 1) + CHUNK_OVERHEAD;
|
228
|
-
};
|
229
|
-
|
230
|
-
Chunk.prototype.getChunkMaps = function(includeEntries, realHash) {
|
231
|
-
var chunksProcessed = [];
|
232
|
-
var chunkHashMap = {};
|
233
|
-
var chunkNameMap = {};
|
234
|
-
(function addChunk(c) {
|
235
|
-
if(chunksProcessed.indexOf(c) >= 0) return;
|
236
|
-
chunksProcessed.push(c);
|
237
|
-
if(!c.entry || includeEntries) {
|
238
|
-
chunkHashMap[c.id] = realHash ? c.hash : c.renderedHash;
|
239
|
-
if(c.name)
|
240
|
-
chunkNameMap[c.id] = c.name;
|
241
|
-
}
|
242
|
-
c.chunks.forEach(addChunk);
|
243
|
-
}(this));
|
244
|
-
return {
|
245
|
-
hash: chunkHashMap,
|
246
|
-
name: chunkNameMap
|
247
|
-
};
|
248
|
-
};
|
249
|
-
|
250
|
-
Chunk.prototype.toString = function() {
|
251
|
-
return "Chunk[" + this.modules.join() + "]";
|
252
|
-
};
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
function Chunk(name, module, loc) {
|
6
|
+
this.id = null;
|
7
|
+
this.ids = null;
|
8
|
+
this.name = name;
|
9
|
+
this.modules = [];
|
10
|
+
this.chunks = [];
|
11
|
+
this.parents = [];
|
12
|
+
this.blocks = [];
|
13
|
+
this.origins = [];
|
14
|
+
this.files = [];
|
15
|
+
this.rendered = false;
|
16
|
+
this.entry = false;
|
17
|
+
this.initial = false;
|
18
|
+
if(module) {
|
19
|
+
this.origins.push({
|
20
|
+
module: module,
|
21
|
+
loc: loc,
|
22
|
+
name: name
|
23
|
+
});
|
24
|
+
}
|
25
|
+
}
|
26
|
+
module.exports = Chunk;
|
27
|
+
|
28
|
+
Chunk.prototype.addModule = function(module) {
|
29
|
+
if(this.modules.indexOf(module) >= 0) {
|
30
|
+
return false;
|
31
|
+
}
|
32
|
+
this.modules.push(module);
|
33
|
+
return true;
|
34
|
+
};
|
35
|
+
|
36
|
+
Chunk.prototype._removeAndDo = require("./removeAndDo");
|
37
|
+
|
38
|
+
Chunk.prototype.removeModule = function(module) {
|
39
|
+
this._removeAndDo("modules", module, "removeChunk");
|
40
|
+
};
|
41
|
+
|
42
|
+
Chunk.prototype.removeChunk = function(chunk) {
|
43
|
+
this._removeAndDo("chunks", chunk, "removeParent");
|
44
|
+
};
|
45
|
+
|
46
|
+
Chunk.prototype.removeParent = function(chunk) {
|
47
|
+
this._removeAndDo("parents", chunk, "removeChunk");
|
48
|
+
};
|
49
|
+
|
50
|
+
function createAdder(collection) {
|
51
|
+
return function(chunk) {
|
52
|
+
if(chunk === this) {
|
53
|
+
return false;
|
54
|
+
}
|
55
|
+
if(this[collection].indexOf(chunk) >= 0) {
|
56
|
+
return false;
|
57
|
+
}
|
58
|
+
this[collection].push(chunk);
|
59
|
+
return true;
|
60
|
+
};
|
61
|
+
}
|
62
|
+
|
63
|
+
Chunk.prototype.addChunk = createAdder("chunks");
|
64
|
+
|
65
|
+
Chunk.prototype.addParent = createAdder("parents");
|
66
|
+
|
67
|
+
Chunk.prototype.addBlock = function(block) {
|
68
|
+
if(this.blocks.indexOf(block) >= 0) {
|
69
|
+
return false;
|
70
|
+
}
|
71
|
+
this.blocks.push(block);
|
72
|
+
return true;
|
73
|
+
};
|
74
|
+
|
75
|
+
Chunk.prototype.addOrigin = function(module, loc) {
|
76
|
+
this.origins.push({
|
77
|
+
module: module,
|
78
|
+
loc: loc,
|
79
|
+
name: this.name
|
80
|
+
});
|
81
|
+
};
|
82
|
+
|
83
|
+
Chunk.prototype.remove = function(reason) {
|
84
|
+
this.modules.slice().forEach(function(m) {
|
85
|
+
m.removeChunk(this);
|
86
|
+
}, this);
|
87
|
+
this.parents.forEach(function(c) {
|
88
|
+
var idx = c.chunks.indexOf(this);
|
89
|
+
if(idx >= 0) {
|
90
|
+
c.chunks.splice(idx, 1);
|
91
|
+
}
|
92
|
+
this.chunks.forEach(function(cc) {
|
93
|
+
cc.addParent(c);
|
94
|
+
});
|
95
|
+
}, this);
|
96
|
+
this.chunks.forEach(function(c) {
|
97
|
+
var idx = c.parents.indexOf(this);
|
98
|
+
if(idx >= 0) {
|
99
|
+
c.parents.splice(idx, 1);
|
100
|
+
}
|
101
|
+
this.parents.forEach(function(cc) {
|
102
|
+
cc.addChunk(c);
|
103
|
+
});
|
104
|
+
}, this);
|
105
|
+
this.blocks.forEach(function(b) {
|
106
|
+
var idx = b.chunks.indexOf(this);
|
107
|
+
if(idx >= 0) {
|
108
|
+
b.chunks.splice(idx, 1);
|
109
|
+
if(b.chunks.length === 0) {
|
110
|
+
b.chunks = null;
|
111
|
+
b.chunkReason = reason;
|
112
|
+
}
|
113
|
+
}
|
114
|
+
}, this);
|
115
|
+
};
|
116
|
+
|
117
|
+
Chunk.prototype.integrate = function(other, reason) {
|
118
|
+
if(!this.canBeIntegrated(other)) {
|
119
|
+
return false;
|
120
|
+
}
|
121
|
+
|
122
|
+
var otherModules = other.modules.slice();
|
123
|
+
otherModules.forEach(function(m) {
|
124
|
+
m.removeChunk(other);
|
125
|
+
m.addChunk(this);
|
126
|
+
this.addModule(m);
|
127
|
+
m.rewriteChunkInReasons(other, [this]);
|
128
|
+
}, this);
|
129
|
+
other.modules.length = 0;
|
130
|
+
|
131
|
+
function moveChunks(chunks, kind, onChunk) {
|
132
|
+
chunks.forEach(function(c) {
|
133
|
+
var idx = c[kind].indexOf(other);
|
134
|
+
if(idx >= 0) {
|
135
|
+
c[kind].splice(idx, 1);
|
136
|
+
}
|
137
|
+
onChunk(c);
|
138
|
+
});
|
139
|
+
}
|
140
|
+
moveChunks(other.parents, "chunks", function(c) {
|
141
|
+
if(c !== this && this.addParent(c)) {
|
142
|
+
c.addChunk(this);
|
143
|
+
}
|
144
|
+
}.bind(this));
|
145
|
+
other.parents.length = 0;
|
146
|
+
moveChunks(other.chunks, "parents", function(c) {
|
147
|
+
if(c !== this && this.addChunk(c)) {
|
148
|
+
c.addParent(this);
|
149
|
+
}
|
150
|
+
}.bind(this));
|
151
|
+
other.chunks.length = 0;
|
152
|
+
other.blocks.forEach(function(b) {
|
153
|
+
b.chunks = (b.chunks || [this]).map(function(c) {
|
154
|
+
return c === other ? this : c;
|
155
|
+
}, this);
|
156
|
+
b.chunkReason = reason;
|
157
|
+
this.addBlock(b);
|
158
|
+
}, this);
|
159
|
+
other.blocks.length = 0;
|
160
|
+
other.origins.forEach(function(origin) {
|
161
|
+
if(!origin.reasons) {
|
162
|
+
origin.reasons = [reason];
|
163
|
+
} else if(origin.reasons[0] !== reason) {
|
164
|
+
origin.reasons.unshift(reason);
|
165
|
+
}
|
166
|
+
this.origins.push(origin);
|
167
|
+
}, this);
|
168
|
+
return true;
|
169
|
+
};
|
170
|
+
|
171
|
+
Chunk.prototype.isEmpty = function() {
|
172
|
+
return this.modules.length === 0;
|
173
|
+
};
|
174
|
+
|
175
|
+
Chunk.prototype.updateHash = function(hash) {
|
176
|
+
hash.update(this.id + " ");
|
177
|
+
hash.update(this.ids ? this.ids.join(",") : "");
|
178
|
+
hash.update(this.name + "");
|
179
|
+
this.modules.forEach(function(m) {
|
180
|
+
m.updateHash(hash);
|
181
|
+
});
|
182
|
+
};
|
183
|
+
|
184
|
+
Chunk.prototype.size = function(options) {
|
185
|
+
var CHUNK_OVERHEAD = options.chunkOverhead || 10000;
|
186
|
+
var ENTRY_CHUNK_MULTIPLICATOR = options.entryChunkMultiplicator || 10;
|
187
|
+
|
188
|
+
var modulesSize = this.modules.reduce(function(a, b) {
|
189
|
+
return a + b.size();
|
190
|
+
}, 0);
|
191
|
+
return modulesSize * (this.initial ? ENTRY_CHUNK_MULTIPLICATOR : 1) + CHUNK_OVERHEAD;
|
192
|
+
};
|
193
|
+
|
194
|
+
Chunk.prototype.canBeIntegrated = function(other) {
|
195
|
+
if(other.initial) {
|
196
|
+
return false;
|
197
|
+
}
|
198
|
+
if(this.initial) {
|
199
|
+
if(other.parents.length !== 1 || other.parents[0] !== this) {
|
200
|
+
return false;
|
201
|
+
}
|
202
|
+
}
|
203
|
+
return true;
|
204
|
+
};
|
205
|
+
|
206
|
+
Chunk.prototype.integratedSize = function(other, options) {
|
207
|
+
// Chunk if it's possible to integrate this chunk
|
208
|
+
if(!this.canBeIntegrated(other)) {
|
209
|
+
return false;
|
210
|
+
}
|
211
|
+
|
212
|
+
var CHUNK_OVERHEAD = options.chunkOverhead || 10000;
|
213
|
+
var ENTRY_CHUNK_MULTIPLICATOR = options.entryChunkMultiplicator || 10;
|
214
|
+
|
215
|
+
var mergedModules = this.modules.slice();
|
216
|
+
other.modules.forEach(function(m) {
|
217
|
+
if(this.modules.indexOf(m) < 0) {
|
218
|
+
mergedModules.push(m);
|
219
|
+
}
|
220
|
+
}, this);
|
221
|
+
|
222
|
+
var modulesSize = mergedModules.map(function(m) {
|
223
|
+
return m.size();
|
224
|
+
}).reduce(function(a, b) {
|
225
|
+
return a + b;
|
226
|
+
}, 0);
|
227
|
+
return modulesSize * (this.initial || other.initial ? ENTRY_CHUNK_MULTIPLICATOR : 1) + CHUNK_OVERHEAD;
|
228
|
+
};
|
229
|
+
|
230
|
+
Chunk.prototype.getChunkMaps = function(includeEntries, realHash) {
|
231
|
+
var chunksProcessed = [];
|
232
|
+
var chunkHashMap = {};
|
233
|
+
var chunkNameMap = {};
|
234
|
+
(function addChunk(c) {
|
235
|
+
if(chunksProcessed.indexOf(c) >= 0) return;
|
236
|
+
chunksProcessed.push(c);
|
237
|
+
if(!c.entry || includeEntries) {
|
238
|
+
chunkHashMap[c.id] = realHash ? c.hash : c.renderedHash;
|
239
|
+
if(c.name)
|
240
|
+
chunkNameMap[c.id] = c.name;
|
241
|
+
}
|
242
|
+
c.chunks.forEach(addChunk);
|
243
|
+
}(this));
|
244
|
+
return {
|
245
|
+
hash: chunkHashMap,
|
246
|
+
name: chunkNameMap
|
247
|
+
};
|
248
|
+
};
|
249
|
+
|
250
|
+
Chunk.prototype.toString = function() {
|
251
|
+
return "Chunk[" + this.modules.join() + "]";
|
252
|
+
};
|
package/lib/ChunkRenderError.js
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
function ChunkRenderError(chunk, file, error) {
|
6
|
-
Error.call(this);
|
7
|
-
Error.captureStackTrace(this, ChunkRenderError);
|
8
|
-
this.name = "ChunkRenderError";
|
9
|
-
this.error = error;
|
10
|
-
this.message = error.message;
|
11
|
-
this.details = error.stack;
|
12
|
-
this.file = file;
|
13
|
-
this.chunk = chunk;
|
14
|
-
}
|
15
|
-
module.exports = ChunkRenderError;
|
16
|
-
|
17
|
-
ChunkRenderError.prototype = Object.create(Error.prototype);
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
function ChunkRenderError(chunk, file, error) {
|
6
|
+
Error.call(this);
|
7
|
+
Error.captureStackTrace(this, ChunkRenderError);
|
8
|
+
this.name = "ChunkRenderError";
|
9
|
+
this.error = error;
|
10
|
+
this.message = error.message;
|
11
|
+
this.details = error.stack;
|
12
|
+
this.file = file;
|
13
|
+
this.chunk = chunk;
|
14
|
+
}
|
15
|
+
module.exports = ChunkRenderError;
|
16
|
+
|
17
|
+
ChunkRenderError.prototype = Object.create(Error.prototype);
|
package/lib/ChunkTemplate.js
CHANGED
@@ -1,37 +1,37 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
var ConcatSource = require("webpack-core/lib/ConcatSource");
|
6
|
-
var Template = require("./Template");
|
7
|
-
|
8
|
-
function ChunkTemplate(outputOptions) {
|
9
|
-
Template.call(this, outputOptions);
|
10
|
-
}
|
11
|
-
|
12
|
-
module.exports = ChunkTemplate;
|
13
|
-
|
14
|
-
ChunkTemplate.prototype = Object.create(Template.prototype);
|
15
|
-
ChunkTemplate.prototype.render = function(chunk, moduleTemplate, dependencyTemplates) {
|
16
|
-
var modules = this.renderChunkModules(chunk, moduleTemplate, dependencyTemplates);
|
17
|
-
var core = this.applyPluginsWaterfall("modules", modules, chunk, moduleTemplate, dependencyTemplates);
|
18
|
-
var source = this.applyPluginsWaterfall("render", core, chunk, moduleTemplate, dependencyTemplates);
|
19
|
-
if(chunk.modules.some(function(module) {
|
20
|
-
return module.id === 0;
|
21
|
-
})) {
|
22
|
-
source = this.applyPluginsWaterfall("render-with-entry", source, chunk);
|
23
|
-
}
|
24
|
-
chunk.rendered = true;
|
25
|
-
return new ConcatSource(source, ";");
|
26
|
-
};
|
27
|
-
|
28
|
-
ChunkTemplate.prototype.updateHash = function(hash) {
|
29
|
-
hash.update("ChunkTemplate");
|
30
|
-
hash.update("2");
|
31
|
-
this.applyPlugins("hash", hash);
|
32
|
-
};
|
33
|
-
|
34
|
-
ChunkTemplate.prototype.updateHashForChunk = function(hash, chunk) {
|
35
|
-
this.updateHash(hash);
|
36
|
-
this.applyPlugins("hash-for-chunk", hash, chunk);
|
37
|
-
};
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
var ConcatSource = require("webpack-core/lib/ConcatSource");
|
6
|
+
var Template = require("./Template");
|
7
|
+
|
8
|
+
function ChunkTemplate(outputOptions) {
|
9
|
+
Template.call(this, outputOptions);
|
10
|
+
}
|
11
|
+
|
12
|
+
module.exports = ChunkTemplate;
|
13
|
+
|
14
|
+
ChunkTemplate.prototype = Object.create(Template.prototype);
|
15
|
+
ChunkTemplate.prototype.render = function(chunk, moduleTemplate, dependencyTemplates) {
|
16
|
+
var modules = this.renderChunkModules(chunk, moduleTemplate, dependencyTemplates);
|
17
|
+
var core = this.applyPluginsWaterfall("modules", modules, chunk, moduleTemplate, dependencyTemplates);
|
18
|
+
var source = this.applyPluginsWaterfall("render", core, chunk, moduleTemplate, dependencyTemplates);
|
19
|
+
if(chunk.modules.some(function(module) {
|
20
|
+
return module.id === 0;
|
21
|
+
})) {
|
22
|
+
source = this.applyPluginsWaterfall("render-with-entry", source, chunk);
|
23
|
+
}
|
24
|
+
chunk.rendered = true;
|
25
|
+
return new ConcatSource(source, ";");
|
26
|
+
};
|
27
|
+
|
28
|
+
ChunkTemplate.prototype.updateHash = function(hash) {
|
29
|
+
hash.update("ChunkTemplate");
|
30
|
+
hash.update("2");
|
31
|
+
this.applyPlugins("hash", hash);
|
32
|
+
};
|
33
|
+
|
34
|
+
ChunkTemplate.prototype.updateHashForChunk = function(hash, chunk) {
|
35
|
+
this.updateHash(hash);
|
36
|
+
this.applyPlugins("hash-for-chunk", hash, chunk);
|
37
|
+
};
|