webpack 2.3.3 → 2.5.1
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/README.md +148 -133
- package/lib/APIPlugin.js +0 -6
- package/lib/AsyncDependenciesBlock.js +1 -1
- package/lib/AutomaticPrefetchPlugin.js +2 -2
- package/lib/BannerPlugin.js +30 -8
- package/lib/CachePlugin.js +2 -2
- package/lib/CaseSensitiveModulesWarning.js +6 -3
- package/lib/ChunkRenderError.js +3 -1
- package/lib/ChunkTemplate.js +2 -2
- package/lib/Compilation.js +17 -17
- package/lib/Compiler.js +30 -25
- package/lib/ContextModule.js +4 -3
- package/lib/ContextModuleFactory.js +5 -5
- package/lib/DelegatedModule.js +69 -63
- package/lib/DependenciesBlock.js +65 -59
- package/lib/Dependency.js +1 -0
- package/lib/EntryModuleNotFoundError.js +16 -10
- package/lib/ExtendedAPIPlugin.js +7 -2
- package/lib/ExternalModule.js +1 -1
- package/lib/ExternalModuleFactoryPlugin.js +26 -23
- package/lib/FlagDependencyUsagePlugin.js +63 -75
- package/lib/HotModuleReplacement.runtime.js +25 -27
- package/lib/HotModuleReplacementPlugin.js +3 -5
- package/lib/IgnorePlugin.js +48 -17
- package/lib/JsonpChunkTemplatePlugin.js +24 -24
- package/lib/JsonpMainTemplatePlugin.js +182 -182
- package/lib/LibManifestPlugin.js +51 -46
- package/lib/MainTemplate.js +17 -18
- package/lib/Module.js +158 -160
- package/lib/ModuleBuildError.js +4 -2
- package/lib/ModuleDependencyError.js +2 -1
- package/lib/ModuleDependencyWarning.js +2 -1
- package/lib/ModuleError.js +2 -2
- package/lib/ModuleFilenameHelpers.js +27 -27
- package/lib/ModuleNotFoundError.js +3 -1
- package/lib/ModuleParseError.js +6 -4
- package/lib/ModuleWarning.js +2 -2
- package/lib/MultiCompiler.js +3 -4
- package/lib/MultiStats.js +3 -3
- package/lib/MultiWatching.js +2 -2
- package/lib/NamedChunksPlugin.js +30 -0
- package/lib/NodeStuffPlugin.js +80 -79
- package/lib/NormalModule.js +7 -3
- package/lib/NormalModuleFactory.js +244 -240
- package/lib/Parser.js +1256 -1079
- package/lib/ProgressPlugin.js +2 -2
- package/lib/RawModule.js +1 -1
- package/lib/RecordIdsPlugin.js +5 -9
- package/lib/SetVarMainTemplatePlugin.js +1 -1
- package/lib/SourceMapDevToolPlugin.js +153 -157
- package/lib/Stats.js +34 -6
- package/lib/TemplatedPathPlugin.js +1 -0
- package/lib/UnsupportedFeatureWarning.js +2 -1
- package/lib/WebpackError.js +11 -0
- package/lib/WebpackOptionsApply.js +4 -4
- package/lib/WebpackOptionsValidationError.js +2 -3
- package/lib/dependencies/AMDDefineDependency.js +10 -6
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -1
- package/lib/dependencies/AMDPlugin.js +3 -3
- package/lib/dependencies/ContextDependencyHelpers.js +19 -16
- package/lib/dependencies/CriticalDependencyWarning.js +4 -1
- package/lib/dependencies/DepBlockHelpers.js +3 -3
- package/lib/dependencies/HarmonyCompatibilityDependency.js +1 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -3
- package/lib/dependencies/ImportContextDependency.js +2 -1
- package/lib/dependencies/ImportDependenciesBlock.js +2 -2
- package/lib/dependencies/ImportParserPlugin.js +16 -2
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +11 -3
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +42 -13
- package/lib/dependencies/RequireEnsureDependency.js +9 -2
- package/lib/formatLocation.js +44 -27
- package/lib/optimize/AggressiveSplittingPlugin.js +10 -17
- package/lib/optimize/CommonsChunkPlugin.js +2 -2
- package/lib/performance/AssetsOverSizeLimitWarning.js +4 -1
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +5 -1
- package/lib/performance/NoAsyncChunksWarning.js +5 -1
- package/lib/removeAndDo.js +6 -4
- package/lib/util/identifier.js +16 -0
- package/lib/webpack.js +2 -1
- package/package.json +7 -4
- package/schemas/webpackOptionsSchema.json +35 -0
package/lib/ChunkRenderError.js
CHANGED
@@ -4,10 +4,12 @@
|
|
4
4
|
*/
|
5
5
|
"use strict";
|
6
6
|
|
7
|
-
|
7
|
+
const WebpackError = require("./WebpackError");
|
8
8
|
|
9
|
+
class ChunkRenderError extends WebpackError {
|
9
10
|
constructor(chunk, file, error) {
|
10
11
|
super();
|
12
|
+
|
11
13
|
this.name = "ChunkRenderError";
|
12
14
|
this.error = error;
|
13
15
|
this.message = error.message;
|
package/lib/ChunkTemplate.js
CHANGED
@@ -13,8 +13,8 @@ module.exports = class ChunkTemplate extends Template {
|
|
13
13
|
}
|
14
14
|
|
15
15
|
render(chunk, moduleTemplate, dependencyTemplates) {
|
16
|
-
const
|
17
|
-
const core = this.applyPluginsWaterfall("modules",
|
16
|
+
const moduleSources = this.renderChunkModules(chunk, moduleTemplate, dependencyTemplates);
|
17
|
+
const core = this.applyPluginsWaterfall("modules", moduleSources, chunk, moduleTemplate, dependencyTemplates);
|
18
18
|
let source = this.applyPluginsWaterfall("render", core, chunk, moduleTemplate, dependencyTemplates);
|
19
19
|
if(chunk.hasEntryModule()) {
|
20
20
|
source = this.applyPluginsWaterfall("render-with-entry", source, chunk);
|
package/lib/Compilation.js
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
*/
|
5
5
|
"use strict";
|
6
6
|
|
7
|
-
const
|
7
|
+
const asyncLib = require("async");
|
8
8
|
const crypto = require("crypto");
|
9
9
|
const Tapable = require("tapable");
|
10
10
|
const EntryModuleNotFoundError = require("./EntryModuleNotFoundError");
|
@@ -14,7 +14,6 @@ const ModuleDependencyError = require("./ModuleDependencyError");
|
|
14
14
|
const Module = require("./Module");
|
15
15
|
const Chunk = require("./Chunk");
|
16
16
|
const Entrypoint = require("./Entrypoint");
|
17
|
-
const Stats = require("./Stats");
|
18
17
|
const MainTemplate = require("./MainTemplate");
|
19
18
|
const ChunkTemplate = require("./ChunkTemplate");
|
20
19
|
const HotUpdateChunkTemplate = require("./HotUpdateChunkTemplate");
|
@@ -22,6 +21,7 @@ const ModuleTemplate = require("./ModuleTemplate");
|
|
22
21
|
const Dependency = require("./Dependency");
|
23
22
|
const ChunkRenderError = require("./ChunkRenderError");
|
24
23
|
const CachedSource = require("webpack-sources").CachedSource;
|
24
|
+
const Stats = require("./Stats");
|
25
25
|
|
26
26
|
function byId(a, b) {
|
27
27
|
if(a.id < b.id) return -1;
|
@@ -82,6 +82,10 @@ class Compilation extends Tapable {
|
|
82
82
|
this.dependencyTemplates = new Map();
|
83
83
|
}
|
84
84
|
|
85
|
+
getStats() {
|
86
|
+
return new Stats(this);
|
87
|
+
}
|
88
|
+
|
85
89
|
templatesPlugin(name, fn) {
|
86
90
|
this.mainTemplate.plugin(name, fn);
|
87
91
|
this.chunkTemplate.plugin(name, fn);
|
@@ -197,7 +201,7 @@ class Compilation extends Tapable {
|
|
197
201
|
|
198
202
|
addModuleDependencies(module, dependencies, bail, cacheGroup, recursive, callback) {
|
199
203
|
let _this = this;
|
200
|
-
const start = _this.profile &&
|
204
|
+
const start = _this.profile && Date.now();
|
201
205
|
|
202
206
|
const factories = [];
|
203
207
|
for(let i = 0; i < dependencies.length; i++) {
|
@@ -207,7 +211,7 @@ class Compilation extends Tapable {
|
|
207
211
|
}
|
208
212
|
factories[i] = [factory, dependencies[i]];
|
209
213
|
}
|
210
|
-
|
214
|
+
asyncLib.forEach(factories, function iteratorFactory(item, callback) {
|
211
215
|
const dependencies = item[1];
|
212
216
|
|
213
217
|
const errorAndCallback = function errorAndCallback(err) {
|
@@ -266,7 +270,7 @@ class Compilation extends Tapable {
|
|
266
270
|
if(!dependentModule.profile) {
|
267
271
|
dependentModule.profile = {};
|
268
272
|
}
|
269
|
-
afterFactory =
|
273
|
+
afterFactory = Date.now();
|
270
274
|
dependentModule.profile.factory = afterFactory - start;
|
271
275
|
}
|
272
276
|
|
@@ -286,7 +290,7 @@ class Compilation extends Tapable {
|
|
286
290
|
if(!module.profile) {
|
287
291
|
module.profile = {};
|
288
292
|
}
|
289
|
-
const time =
|
293
|
+
const time = Date.now() - start;
|
290
294
|
if(!module.profile.dependencies || time > module.profile.dependencies) {
|
291
295
|
module.profile.dependencies = time;
|
292
296
|
}
|
@@ -307,7 +311,7 @@ class Compilation extends Tapable {
|
|
307
311
|
iterationDependencies(dependencies);
|
308
312
|
|
309
313
|
if(_this.profile) {
|
310
|
-
const afterBuilding =
|
314
|
+
const afterBuilding = Date.now();
|
311
315
|
module.profile.building = afterBuilding - afterFactory;
|
312
316
|
}
|
313
317
|
|
@@ -328,7 +332,7 @@ class Compilation extends Tapable {
|
|
328
332
|
}
|
329
333
|
|
330
334
|
if(_this.profile) {
|
331
|
-
const afterBuilding =
|
335
|
+
const afterBuilding = Date.now();
|
332
336
|
dependentModule.profile.building = afterBuilding - afterFactory;
|
333
337
|
}
|
334
338
|
|
@@ -356,7 +360,7 @@ class Compilation extends Tapable {
|
|
356
360
|
}
|
357
361
|
|
358
362
|
_addModuleChain(context, dependency, onModule, callback) {
|
359
|
-
const start = this.profile &&
|
363
|
+
const start = this.profile && Date.now();
|
360
364
|
|
361
365
|
const errorAndCallback = this.bail ? function errorAndCallback(err) {
|
362
366
|
callback(err);
|
@@ -393,7 +397,7 @@ class Compilation extends Tapable {
|
|
393
397
|
if(!module.profile) {
|
394
398
|
module.profile = {};
|
395
399
|
}
|
396
|
-
afterFactory =
|
400
|
+
afterFactory = Date.now();
|
397
401
|
module.profile.factory = afterFactory - start;
|
398
402
|
}
|
399
403
|
|
@@ -404,7 +408,7 @@ class Compilation extends Tapable {
|
|
404
408
|
onModule(module);
|
405
409
|
|
406
410
|
if(this.profile) {
|
407
|
-
const afterBuilding =
|
411
|
+
const afterBuilding = Date.now();
|
408
412
|
module.profile.building = afterBuilding - afterFactory;
|
409
413
|
}
|
410
414
|
|
@@ -432,7 +436,7 @@ class Compilation extends Tapable {
|
|
432
436
|
}
|
433
437
|
|
434
438
|
if(this.profile) {
|
435
|
-
const afterBuilding =
|
439
|
+
const afterBuilding = Date.now();
|
436
440
|
module.profile.building = afterBuilding - afterFactory;
|
437
441
|
}
|
438
442
|
|
@@ -474,7 +478,7 @@ class Compilation extends Tapable {
|
|
474
478
|
const idx = this.preparedChunks.indexOf(slot);
|
475
479
|
this.preparedChunks.splice(idx, 1);
|
476
480
|
}
|
477
|
-
return callback();
|
481
|
+
return callback(null, module);
|
478
482
|
});
|
479
483
|
}
|
480
484
|
|
@@ -1214,10 +1218,6 @@ class Compilation extends Tapable {
|
|
1214
1218
|
return this.mainTemplate.applyPluginsWaterfall("asset-path", filename, data);
|
1215
1219
|
}
|
1216
1220
|
|
1217
|
-
getStats() {
|
1218
|
-
return new Stats(this);
|
1219
|
-
}
|
1220
|
-
|
1221
1221
|
createChildCompiler(name, outputOptions) {
|
1222
1222
|
return this.compiler.createChildCompiler(this, name, outputOptions);
|
1223
1223
|
}
|
package/lib/Compiler.js
CHANGED
@@ -6,15 +6,13 @@ var path = require("path");
|
|
6
6
|
var Tapable = require("tapable");
|
7
7
|
|
8
8
|
var Compilation = require("./Compilation");
|
9
|
-
|
9
|
+
var Stats = require("./Stats");
|
10
10
|
var NormalModuleFactory = require("./NormalModuleFactory");
|
11
11
|
var ContextModuleFactory = require("./ContextModuleFactory");
|
12
12
|
|
13
13
|
function Watching(compiler, watchOptions, handler) {
|
14
14
|
this.startTime = null;
|
15
15
|
this.invalid = false;
|
16
|
-
this.error = null;
|
17
|
-
this.stats = null;
|
18
16
|
this.handler = handler;
|
19
17
|
this.closed = false;
|
20
18
|
if(typeof watchOptions === "number") {
|
@@ -38,7 +36,7 @@ function Watching(compiler, watchOptions, handler) {
|
|
38
36
|
|
39
37
|
Watching.prototype._go = function() {
|
40
38
|
var self = this;
|
41
|
-
self.startTime =
|
39
|
+
self.startTime = Date.now();
|
42
40
|
self.running = true;
|
43
41
|
self.invalid = false;
|
44
42
|
self.compiler.applyPluginsAsync("watch-run", self, function(err) {
|
@@ -61,9 +59,9 @@ Watching.prototype._go = function() {
|
|
61
59
|
if(compilation.applyPluginsBailResult("need-additional-pass")) {
|
62
60
|
compilation.needAdditionalPass = true;
|
63
61
|
|
64
|
-
var stats = compilation
|
62
|
+
var stats = new Stats(compilation);
|
65
63
|
stats.startTime = self.startTime;
|
66
|
-
stats.endTime =
|
64
|
+
stats.endTime = Date.now();
|
67
65
|
self.compiler.applyPlugins("done", stats);
|
68
66
|
|
69
67
|
self.compiler.applyPluginsAsync("additional-pass", function(err) {
|
@@ -79,22 +77,29 @@ Watching.prototype._go = function() {
|
|
79
77
|
});
|
80
78
|
};
|
81
79
|
|
80
|
+
Watching.prototype._getStats = function(compilation) {
|
81
|
+
var stats = new Stats(compilation);
|
82
|
+
stats.startTime = this.startTime;
|
83
|
+
stats.endTime = Date.now();
|
84
|
+
return stats;
|
85
|
+
};
|
86
|
+
|
82
87
|
Watching.prototype._done = function(err, compilation) {
|
83
88
|
this.running = false;
|
84
89
|
if(this.invalid) return this._go();
|
85
|
-
|
86
|
-
|
87
|
-
if(
|
88
|
-
this.
|
89
|
-
this.stats
|
90
|
+
|
91
|
+
var stats = compilation ? this._getStats(compilation) : null;
|
92
|
+
if(err) {
|
93
|
+
this.compiler.applyPlugins("failed", err);
|
94
|
+
this.handler(err, stats);
|
95
|
+
return;
|
90
96
|
}
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
this.handler(this.error, this.stats);
|
96
|
-
if(!this.error && !this.closed)
|
97
|
+
|
98
|
+
this.compiler.applyPlugins("done", stats);
|
99
|
+
this.handler(null, stats);
|
100
|
+
if(!this.closed) {
|
97
101
|
this.watch(compilation.fileDependencies, compilation.contextDependencies, compilation.missingDependencies);
|
102
|
+
}
|
98
103
|
};
|
99
104
|
|
100
105
|
Watching.prototype.watch = function(files, dirs, missing) {
|
@@ -217,7 +222,7 @@ Compiler.prototype.watch = function(watchOptions, handler) {
|
|
217
222
|
|
218
223
|
Compiler.prototype.run = function(callback) {
|
219
224
|
var self = this;
|
220
|
-
var startTime =
|
225
|
+
var startTime = Date.now();
|
221
226
|
|
222
227
|
self.applyPluginsAsync("before-run", self, function(err) {
|
223
228
|
if(err) return callback(err);
|
@@ -232,9 +237,9 @@ Compiler.prototype.run = function(callback) {
|
|
232
237
|
if(err) return callback(err);
|
233
238
|
|
234
239
|
if(self.applyPluginsBailResult("should-emit", compilation) === false) {
|
235
|
-
var stats = compilation
|
240
|
+
var stats = new Stats(compilation);
|
236
241
|
stats.startTime = startTime;
|
237
|
-
stats.endTime =
|
242
|
+
stats.endTime = Date.now();
|
238
243
|
self.applyPlugins("done", stats);
|
239
244
|
return callback(null, stats);
|
240
245
|
}
|
@@ -245,9 +250,9 @@ Compiler.prototype.run = function(callback) {
|
|
245
250
|
if(compilation.applyPluginsBailResult("need-additional-pass")) {
|
246
251
|
compilation.needAdditionalPass = true;
|
247
252
|
|
248
|
-
var stats = compilation
|
253
|
+
var stats = new Stats(compilation);
|
249
254
|
stats.startTime = startTime;
|
250
|
-
stats.endTime =
|
255
|
+
stats.endTime = Date.now();
|
251
256
|
self.applyPlugins("done", stats);
|
252
257
|
|
253
258
|
self.applyPluginsAsync("additional-pass", function(err) {
|
@@ -260,9 +265,9 @@ Compiler.prototype.run = function(callback) {
|
|
260
265
|
self.emitRecords(function(err) {
|
261
266
|
if(err) return callback(err);
|
262
267
|
|
263
|
-
var stats = compilation
|
268
|
+
var stats = new Stats(compilation);
|
264
269
|
stats.startTime = startTime;
|
265
|
-
stats.endTime =
|
270
|
+
stats.endTime = Date.now();
|
266
271
|
self.applyPlugins("done", stats);
|
267
272
|
return callback(null, stats);
|
268
273
|
});
|
@@ -391,7 +396,7 @@ Compiler.prototype.readRecords = function readRecords(callback) {
|
|
391
396
|
if(err) return callback(err);
|
392
397
|
|
393
398
|
try {
|
394
|
-
self.records = JSON.parse(content);
|
399
|
+
self.records = JSON.parse(content.toString("utf-8"));
|
395
400
|
} catch(e) {
|
396
401
|
e.message = "Cannot parse records: " + e.message;
|
397
402
|
return callback(e);
|
package/lib/ContextModule.js
CHANGED
@@ -10,7 +10,7 @@ const RawSource = require("webpack-sources").RawSource;
|
|
10
10
|
const AsyncDependenciesBlock = require("./AsyncDependenciesBlock");
|
11
11
|
|
12
12
|
class ContextModule extends Module {
|
13
|
-
constructor(resolveDependencies, context, recursive, regExp, addon, isAsync) {
|
13
|
+
constructor(resolveDependencies, context, recursive, regExp, addon, isAsync, chunkName) {
|
14
14
|
super();
|
15
15
|
this.resolveDependencies = resolveDependencies;
|
16
16
|
this.context = context;
|
@@ -21,6 +21,7 @@ class ContextModule extends Module {
|
|
21
21
|
this.cacheable = true;
|
22
22
|
this.contextDependencies = [context];
|
23
23
|
this.built = false;
|
24
|
+
this.chunkName = chunkName;
|
24
25
|
}
|
25
26
|
|
26
27
|
prettyRegExp(regexString) {
|
@@ -98,7 +99,7 @@ class ContextModule extends Module {
|
|
98
99
|
|
99
100
|
build(options, compilation, resolver, fs, callback) {
|
100
101
|
this.built = true;
|
101
|
-
this.builtTime =
|
102
|
+
this.builtTime = Date.now();
|
102
103
|
this.resolveDependencies(fs, this.context, this.recursive, this.regExp, (err, dependencies) => {
|
103
104
|
if(err) return callback(err);
|
104
105
|
|
@@ -125,7 +126,7 @@ class ContextModule extends Module {
|
|
125
126
|
// if we are async however create a new async dependency block
|
126
127
|
// and add that block to this context
|
127
128
|
dependencies.forEach(dep => {
|
128
|
-
const block = new AsyncDependenciesBlock(
|
129
|
+
const block = new AsyncDependenciesBlock(this.chunkName, dep.module, dep.loc);
|
129
130
|
block.addDependency(dep);
|
130
131
|
this.addBlock(block);
|
131
132
|
});
|
@@ -2,7 +2,7 @@
|
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
|
-
var
|
5
|
+
var asyncLib = require("async");
|
6
6
|
var path = require("path");
|
7
7
|
|
8
8
|
var Tapable = require("tapable");
|
@@ -61,7 +61,7 @@ ContextModuleFactory.prototype.create = function(data, callback) {
|
|
61
61
|
|
62
62
|
var resolvers = module.resolvers;
|
63
63
|
|
64
|
-
|
64
|
+
asyncLib.parallel([
|
65
65
|
function(callback) {
|
66
66
|
resolvers.context.resolve({}, context, resource, function(err, result) {
|
67
67
|
if(err) return callback(err);
|
@@ -69,7 +69,7 @@ ContextModuleFactory.prototype.create = function(data, callback) {
|
|
69
69
|
});
|
70
70
|
},
|
71
71
|
function(callback) {
|
72
|
-
|
72
|
+
asyncLib.map(loaders, function(loader, callback) {
|
73
73
|
resolvers.loader.resolve({}, context, loader, function(err, result) {
|
74
74
|
if(err) return callback(err);
|
75
75
|
callback(null, result);
|
@@ -93,7 +93,7 @@ ContextModuleFactory.prototype.create = function(data, callback) {
|
|
93
93
|
// Ignored
|
94
94
|
if(!result) return callback();
|
95
95
|
|
96
|
-
return callback(null, new ContextModule(result.resolveDependencies, result.resource, result.recursive, result.regExp, result.loaders, result.async));
|
96
|
+
return callback(null, new ContextModule(result.resolveDependencies, result.resource, result.recursive, result.regExp, result.loaders, result.async, dependency.chunkName));
|
97
97
|
});
|
98
98
|
});
|
99
99
|
});
|
@@ -106,7 +106,7 @@ ContextModuleFactory.prototype.resolveDependencies = function resolveDependencie
|
|
106
106
|
fs.readdir(directory, function(err, files) {
|
107
107
|
if(err) return callback(err);
|
108
108
|
if(!files || files.length === 0) return callback(null, []);
|
109
|
-
|
109
|
+
asyncLib.map(files.filter(function(p) {
|
110
110
|
return p.indexOf(".") !== 0;
|
111
111
|
}), function(seqment, callback) {
|
112
112
|
|
package/lib/DelegatedModule.js
CHANGED
@@ -2,79 +2,85 @@
|
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
|
-
|
6
|
-
var OriginalSource = require("webpack-sources").OriginalSource;
|
7
|
-
var RawSource = require("webpack-sources").RawSource;
|
8
|
-
var WebpackMissingModule = require("./dependencies/WebpackMissingModule");
|
9
|
-
var DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
|
5
|
+
"use strict";
|
10
6
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
this.type = type;
|
17
|
-
this.userRequest = userRequest;
|
18
|
-
this.built = false;
|
19
|
-
this.delegateData = data;
|
20
|
-
}
|
21
|
-
module.exports = DelegatedModule;
|
7
|
+
const Module = require("./Module");
|
8
|
+
const OriginalSource = require("webpack-sources").OriginalSource;
|
9
|
+
const RawSource = require("webpack-sources").RawSource;
|
10
|
+
const WebpackMissingModule = require("./dependencies/WebpackMissingModule");
|
11
|
+
const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
|
22
12
|
|
23
|
-
DelegatedModule
|
24
|
-
|
13
|
+
class DelegatedModule extends Module {
|
14
|
+
constructor(sourceRequest, data, type, userRequest) {
|
15
|
+
super();
|
16
|
+
this.sourceRequest = sourceRequest;
|
17
|
+
this.request = data.id;
|
18
|
+
this.meta = data.meta;
|
19
|
+
this.type = type;
|
20
|
+
this.userRequest = userRequest;
|
21
|
+
this.built = false;
|
22
|
+
this.delegated = true;
|
23
|
+
this.delegateData = data;
|
24
|
+
}
|
25
25
|
|
26
|
-
|
26
|
+
identifier() {
|
27
|
+
return `delegated ${JSON.stringify(this.request)} from ${this.sourceRequest}`;
|
28
|
+
}
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
}
|
30
|
+
readableIdentifier() {
|
31
|
+
return `delegated ${this.userRequest} from ${this.sourceRequest}`;
|
32
|
+
}
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
}
|
34
|
+
needRebuild() {
|
35
|
+
return false;
|
36
|
+
}
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
38
|
+
build(options, compilation, resolver, fs, callback) {
|
39
|
+
this.built = true;
|
40
|
+
this.builtTime = Date.now();
|
41
|
+
this.usedExports = true;
|
42
|
+
this.providedExports = this.delegateData.exports || true;
|
43
|
+
this.dependencies.length = 0;
|
44
|
+
this.addDependency(new DelegatedSourceDependency(this.sourceRequest));
|
45
|
+
callback();
|
46
|
+
}
|
39
47
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
this.providedExports = this.delegateData.exports || true;
|
45
|
-
this.dependencies.length = 0;
|
46
|
-
this.addDependency(new DelegatedSourceDependency(this.sourceRequest));
|
47
|
-
callback();
|
48
|
-
};
|
48
|
+
unbuild() {
|
49
|
+
this.built = false;
|
50
|
+
super.unbuild();
|
51
|
+
}
|
49
52
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
};
|
53
|
+
source() {
|
54
|
+
const sourceModule = this.dependencies[0].module;
|
55
|
+
let str;
|
54
56
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
57
|
+
if(!sourceModule) {
|
58
|
+
str = WebpackMissingModule.moduleCode(this.sourceRequest);
|
59
|
+
} else {
|
60
|
+
str = `module.exports = (__webpack_require__(${sourceModule.id}))`;
|
61
|
+
|
62
|
+
switch(this.type) {
|
63
|
+
case "require":
|
64
|
+
str += `(${JSON.stringify(this.request)})`;
|
65
|
+
break;
|
66
|
+
case "object":
|
67
|
+
str += `[${JSON.stringify(this.request)}]`;
|
68
|
+
break;
|
69
|
+
}
|
70
|
+
|
71
|
+
str += ";";
|
72
|
+
}
|
73
|
+
|
74
|
+
if(this.useSourceMap) {
|
75
|
+
return new OriginalSource(str, this.identifier());
|
76
|
+
} else {
|
77
|
+
return new RawSource(str);
|
69
78
|
}
|
70
79
|
}
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
return new RawSource(str);
|
80
|
+
|
81
|
+
size() {
|
82
|
+
return 42;
|
75
83
|
}
|
76
|
-
}
|
84
|
+
}
|
77
85
|
|
78
|
-
|
79
|
-
return 42;
|
80
|
-
};
|
86
|
+
module.exports = DelegatedModule;
|
package/lib/DependenciesBlock.js
CHANGED
@@ -1,75 +1,81 @@
|
|
1
1
|
/*
|
2
|
-
|
3
|
-
|
4
|
-
*/
|
5
|
-
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
const DependenciesBlockVariable = require("./DependenciesBlockVariable");
|
8
|
+
|
9
|
+
function disconnect(i) {
|
10
|
+
i.disconnect();
|
11
11
|
}
|
12
|
-
module.exports = DependenciesBlock;
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
function unseal(i) {
|
14
|
+
i.unseal();
|
15
|
+
}
|
16
|
+
|
17
|
+
class DependenciesBlock {
|
18
|
+
constructor() {
|
19
|
+
this.dependencies = [];
|
20
|
+
this.blocks = [];
|
21
|
+
this.variables = [];
|
22
|
+
}
|
23
|
+
|
24
|
+
addBlock(block) {
|
25
|
+
this.blocks.push(block);
|
26
|
+
block.parent = this;
|
27
|
+
}
|
28
|
+
|
29
|
+
addVariable(name, expression, dependencies) {
|
30
|
+
for(let v of this.variables) {
|
31
|
+
if(v.name === name && v.expression === expression) {
|
32
|
+
return;
|
33
|
+
}
|
34
|
+
}
|
35
|
+
this.variables.push(new DependenciesBlockVariable(name, expression, dependencies));
|
36
|
+
}
|
18
37
|
|
19
|
-
|
20
|
-
|
21
|
-
var v = this.variables[i];
|
22
|
-
if(v.name === name && v.expression === expression) return;
|
38
|
+
addDependency(dependency) {
|
39
|
+
this.dependencies.push(dependency);
|
23
40
|
}
|
24
|
-
this.variables.push(new DependenciesBlockVariable(name, expression, dependencies));
|
25
|
-
};
|
26
41
|
|
27
|
-
|
28
|
-
|
29
|
-
|
42
|
+
updateHash(hash) {
|
43
|
+
function updateHash(i) {
|
44
|
+
i.updateHash(hash);
|
45
|
+
}
|
30
46
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
}
|
35
|
-
this.blocks.forEach(function(b) {
|
36
|
-
b.updateHash(hash);
|
37
|
-
});
|
38
|
-
this.variables.forEach(function(v) {
|
39
|
-
v.updateHash(hash);
|
40
|
-
});
|
41
|
-
};
|
47
|
+
this.dependencies.forEach(updateHash);
|
48
|
+
this.blocks.forEach(updateHash);
|
49
|
+
this.variables.forEach(updateHash);
|
50
|
+
}
|
42
51
|
|
43
|
-
|
44
|
-
|
45
|
-
|
52
|
+
disconnect() {
|
53
|
+
this.dependencies.forEach(disconnect);
|
54
|
+
this.blocks.forEach(disconnect);
|
55
|
+
this.variables.forEach(disconnect);
|
46
56
|
}
|
47
|
-
this.dependencies.forEach(disconnect);
|
48
|
-
this.blocks.forEach(disconnect);
|
49
|
-
this.variables.forEach(disconnect);
|
50
|
-
};
|
51
57
|
|
52
|
-
|
53
|
-
|
54
|
-
i.unseal();
|
58
|
+
unseal() {
|
59
|
+
this.blocks.forEach(unseal);
|
55
60
|
}
|
56
|
-
this.blocks.forEach(unseal);
|
57
|
-
};
|
58
61
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
62
|
+
hasDependencies(filter) {
|
63
|
+
if(filter) {
|
64
|
+
if(this.dependencies.some(filter)) {
|
65
|
+
return true;
|
66
|
+
}
|
67
|
+
} else {
|
68
|
+
if(this.dependencies.length > 0) {
|
69
|
+
return true;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
return this.blocks.concat(this.variables).some(item => item.hasDependencies(filter));
|
64
74
|
}
|
65
75
|
|
66
|
-
|
67
|
-
|
68
|
-
}
|
69
|
-
}
|
76
|
+
sortItems() {
|
77
|
+
this.blocks.forEach(block => block.sortItems());
|
78
|
+
}
|
79
|
+
}
|
70
80
|
|
71
|
-
|
72
|
-
this.blocks.forEach(function(block) {
|
73
|
-
block.sortItems();
|
74
|
-
});
|
75
|
-
};
|
81
|
+
module.exports = DependenciesBlock;
|