webpack 2.4.1 → 2.6.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 +9 -1
- package/lib/BannerPlugin.js +30 -8
- package/lib/Compilation.js +14 -14
- package/lib/Compiler.js +29 -24
- package/lib/ContextModule.js +133 -33
- package/lib/DelegatedModule.js +3 -1
- package/lib/ExternalModule.js +1 -1
- package/lib/FunctionModuleTemplatePlugin.js +1 -1
- package/lib/HotModuleReplacement.runtime.js +3 -1
- package/lib/IgnorePlugin.js +2 -2
- package/lib/JsonpMainTemplatePlugin.js +8 -7
- package/lib/LibManifestPlugin.js +1 -1
- package/lib/NormalModule.js +1 -1
- package/lib/Parser.js +33 -20
- package/lib/ProgressPlugin.js +2 -2
- package/lib/RawModule.js +1 -1
- package/lib/Stats.js +2 -1
- package/lib/Template.js +5 -0
- package/lib/WebpackOptionsApply.js +3 -3
- package/lib/WebpackOptionsDefaulter.js +1 -0
- package/lib/dependencies/DepBlockHelpers.js +1 -1
- package/lib/dependencies/HarmonyCompatibilityDependency.js +1 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +1 -1
- package/lib/dependencies/ImportContextDependency.js +0 -1
- package/lib/dependencies/ImportDependency.js +1 -1
- package/lib/dependencies/ImportEagerContextDependency.js +22 -0
- package/lib/dependencies/ImportEagerDependency.js +46 -0
- package/lib/dependencies/ImportLazyContextDependency.js +22 -0
- package/lib/dependencies/ImportLazyOnceContextDependency.js +22 -0
- package/lib/dependencies/ImportParserPlugin.js +37 -6
- package/lib/dependencies/ImportPlugin.js +15 -3
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +1 -7
- package/lib/formatLocation.js +44 -27
- package/lib/node/NodeSourcePlugin.js +72 -70
- package/lib/optimize/CommonsChunkPlugin.js +1 -1
- package/lib/webworker/WebWorkerMainTemplatePlugin.js +18 -14
- package/package.json +6 -4
- package/schemas/webpackOptionsSchema.json +12 -0
package/README.md
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
[![tests][tests]][tests-url]
|
5
5
|
[![builds][builds]][builds-url]
|
6
6
|
[![coverage][cover]][cover-url]
|
7
|
+
[![licenses][licenses]][licenses-url]
|
7
8
|
|
8
9
|
<div align="center">
|
9
10
|
<a href="https://github.com/webpack/webpack">
|
@@ -255,6 +256,10 @@ You are also welcome to correct any spelling mistakes or any language issues.
|
|
255
256
|
|
256
257
|
If you want to discuss something or just need help, [here is our Gitter room](https://gitter.im/webpack/webpack).
|
257
258
|
|
259
|
+
### License
|
260
|
+
|
261
|
+
[](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fwebpack%2Fwebpack?ref=badge_large)
|
262
|
+
|
258
263
|
<h2 align="center">Core Team</h2>
|
259
264
|
|
260
265
|
<table>
|
@@ -333,7 +338,7 @@ This is how we use the donations:
|
|
333
338
|
|
334
339
|
<h2 align="center">Other Backers and Sponsors</h2>
|
335
340
|
|
336
|
-
|
341
|
+
Before we started using OpenCollective, donations were made anonymously. Now that we have made the switch, we would like to acknowledge these sponsors (and the ones who continue to donate using OpenCollective). If we've missed someone, please send us a PR, and we'll add you to this list.
|
337
342
|
|
338
343
|
[Google Angular Team](https://angular.io/), [Architects.io](http://architects.io/),
|
339
344
|
<a href="https://moonmail.io" target="_blank" title="Email Marketing Software"><img
|
@@ -511,5 +516,8 @@ src="https://static.monei.net/monei-logo.svg" height="30" alt="MONEI"></a>
|
|
511
516
|
[builds-url]: https://ci.appveyor.com/project/sokra/webpack/branch/master
|
512
517
|
[builds]: https://ci.appveyor.com/api/projects/status/github/webpack/webpack?svg=true
|
513
518
|
|
519
|
+
[licenses-url]: https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fwebpack%2Fwebpack?ref=badge_shield
|
520
|
+
[licenses]: https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fwebpack%2Fwebpack.svg?type=shield
|
521
|
+
|
514
522
|
[cover]: https://img.shields.io/coveralls/webpack/webpack.svg
|
515
523
|
[cover-url]: https://coveralls.io/r/webpack/webpack/
|
package/lib/BannerPlugin.js
CHANGED
@@ -8,10 +8,10 @@
|
|
8
8
|
const ConcatSource = require("webpack-sources").ConcatSource;
|
9
9
|
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
10
10
|
|
11
|
-
|
11
|
+
const wrapComment = (str) => {
|
12
12
|
if(!str.includes("\n")) return `/*! ${str} */`;
|
13
13
|
return `/*!\n * ${str.split("\n").join("\n * ")}\n */`;
|
14
|
-
}
|
14
|
+
};
|
15
15
|
|
16
16
|
class BannerPlugin {
|
17
17
|
constructor(options) {
|
@@ -33,14 +33,36 @@ class BannerPlugin {
|
|
33
33
|
compilation.plugin("optimize-chunk-assets", (chunks, callback) => {
|
34
34
|
chunks.forEach((chunk) => {
|
35
35
|
if(options.entryOnly && !chunk.isInitial()) return;
|
36
|
-
|
37
36
|
chunk.files
|
38
37
|
.filter(ModuleFilenameHelpers.matchObject.bind(undefined, options))
|
39
|
-
.forEach((file) =>
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
.forEach((file) => {
|
39
|
+
let basename;
|
40
|
+
let query = "";
|
41
|
+
let filename = file;
|
42
|
+
const hash = compilation.hash;
|
43
|
+
const querySplit = filename.indexOf("?");
|
44
|
+
|
45
|
+
if(querySplit >= 0) {
|
46
|
+
query = filename.substr(querySplit);
|
47
|
+
filename = filename.substr(0, querySplit);
|
48
|
+
}
|
49
|
+
|
50
|
+
if(filename.indexOf("/") < 0) {
|
51
|
+
basename = filename;
|
52
|
+
} else {
|
53
|
+
basename = filename.substr(filename.lastIndexOf("/") + 1);
|
54
|
+
}
|
55
|
+
|
56
|
+
const comment = compilation.getPath(banner, {
|
57
|
+
hash,
|
58
|
+
chunk,
|
59
|
+
filename,
|
60
|
+
basename,
|
61
|
+
query,
|
62
|
+
});
|
63
|
+
|
64
|
+
return compilation.assets[file] = new ConcatSource(comment, "\n", compilation.assets[file]);
|
65
|
+
});
|
44
66
|
});
|
45
67
|
callback();
|
46
68
|
});
|
package/lib/Compilation.js
CHANGED
@@ -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++) {
|
@@ -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
|
|
@@ -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
|
});
|
package/lib/ContextModule.js
CHANGED
@@ -8,16 +8,18 @@ const Module = require("./Module");
|
|
8
8
|
const OriginalSource = require("webpack-sources").OriginalSource;
|
9
9
|
const RawSource = require("webpack-sources").RawSource;
|
10
10
|
const AsyncDependenciesBlock = require("./AsyncDependenciesBlock");
|
11
|
+
const DepBlockHelpers = require("./dependencies/DepBlockHelpers");
|
12
|
+
const Template = require("./Template");
|
11
13
|
|
12
14
|
class ContextModule extends Module {
|
13
|
-
constructor(resolveDependencies, context, recursive, regExp, addon,
|
15
|
+
constructor(resolveDependencies, context, recursive, regExp, addon, asyncMode, chunkName) {
|
14
16
|
super();
|
15
17
|
this.resolveDependencies = resolveDependencies;
|
16
18
|
this.context = context;
|
17
19
|
this.recursive = recursive;
|
18
20
|
this.regExp = regExp;
|
19
21
|
this.addon = addon;
|
20
|
-
this.async =
|
22
|
+
this.async = asyncMode;
|
21
23
|
this.cacheable = true;
|
22
24
|
this.contextDependencies = [context];
|
23
25
|
this.built = false;
|
@@ -44,7 +46,7 @@ class ContextModule extends Module {
|
|
44
46
|
identifier() {
|
45
47
|
let identifier = this.context;
|
46
48
|
if(this.async)
|
47
|
-
identifier +=
|
49
|
+
identifier += ` ${this.async}`;
|
48
50
|
if(!this.recursive)
|
49
51
|
identifier += " nonrecursive";
|
50
52
|
if(this.addon)
|
@@ -58,7 +60,7 @@ class ContextModule extends Module {
|
|
58
60
|
readableIdentifier(requestShortener) {
|
59
61
|
let identifier = requestShortener.shorten(this.context);
|
60
62
|
if(this.async)
|
61
|
-
identifier +=
|
63
|
+
identifier += ` ${this.async}`;
|
62
64
|
if(!this.recursive)
|
63
65
|
identifier += " nonrecursive";
|
64
66
|
if(this.addon)
|
@@ -72,7 +74,7 @@ class ContextModule extends Module {
|
|
72
74
|
libIdent(options) {
|
73
75
|
let identifier = this.contextify(options.context, this.context);
|
74
76
|
if(this.async)
|
75
|
-
identifier +=
|
77
|
+
identifier += ` ${this.async}`;
|
76
78
|
if(this.recursive)
|
77
79
|
identifier += " recursive";
|
78
80
|
if(this.addon)
|
@@ -99,46 +101,71 @@ class ContextModule extends Module {
|
|
99
101
|
|
100
102
|
build(options, compilation, resolver, fs, callback) {
|
101
103
|
this.built = true;
|
102
|
-
this.builtTime =
|
104
|
+
this.builtTime = Date.now();
|
103
105
|
this.resolveDependencies(fs, this.context, this.recursive, this.regExp, (err, dependencies) => {
|
104
106
|
if(err) return callback(err);
|
105
107
|
|
108
|
+
// Reset children
|
109
|
+
this.dependencies = [];
|
110
|
+
this.blocks = [];
|
111
|
+
|
112
|
+
// abort if something failed
|
113
|
+
// this will create an empty context
|
106
114
|
if(!dependencies) {
|
107
|
-
this.dependencies = [];
|
108
115
|
callback();
|
109
116
|
return;
|
110
117
|
}
|
111
118
|
|
112
|
-
// enhance dependencies
|
119
|
+
// enhance dependencies with meta info
|
113
120
|
dependencies.forEach(dep => {
|
114
121
|
dep.loc = dep.userRequest;
|
115
122
|
dep.request = this.addon + dep.request;
|
116
123
|
});
|
117
124
|
|
118
|
-
|
119
|
-
|
120
|
-
|
125
|
+
if(!this.async || this.async === "eager") {
|
126
|
+
|
127
|
+
// if we have an sync or eager context
|
128
|
+
// just add all dependencies and continue
|
121
129
|
this.dependencies = dependencies;
|
122
|
-
callback();
|
123
|
-
return;
|
124
|
-
}
|
125
130
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
131
|
+
} else if(this.async === "lazy-once") {
|
132
|
+
|
133
|
+
// for the lazy-once mode create a new async dependency block
|
134
|
+
// and add that block to this context
|
135
|
+
if(dependencies.length > 0) {
|
136
|
+
const block = new AsyncDependenciesBlock(this.chunkName, this);
|
137
|
+
dependencies.forEach(dep => {
|
138
|
+
block.addDependency(dep);
|
139
|
+
});
|
140
|
+
this.addBlock(block);
|
141
|
+
}
|
142
|
+
|
143
|
+
} else {
|
144
|
+
|
145
|
+
// if we are lazy create a new async dependency block per dependency
|
146
|
+
// and add all blocks to this context
|
147
|
+
dependencies.forEach((dep, idx) => {
|
148
|
+
let chunkName = this.chunkName;
|
149
|
+
if(chunkName) {
|
150
|
+
if(!/\[(index|request)\]/.test(chunkName))
|
151
|
+
chunkName += "[index]";
|
152
|
+
chunkName = chunkName.replace(/\[index\]/g, idx);
|
153
|
+
chunkName = chunkName.replace(/\[request\]/g, Template.toPath(dep.userRequest));
|
154
|
+
}
|
155
|
+
const block = new AsyncDependenciesBlock(chunkName, dep.module, dep.loc);
|
156
|
+
block.addDependency(dep);
|
157
|
+
this.addBlock(block);
|
158
|
+
});
|
159
|
+
}
|
133
160
|
callback();
|
134
161
|
});
|
135
162
|
}
|
136
163
|
|
137
|
-
|
164
|
+
getUserRequestMap(dependencies) {
|
138
165
|
// if we filter first we get a new array
|
139
166
|
// therefor we dont need to create a clone of dependencies explicitly
|
140
167
|
// therefore the order of this is !important!
|
141
|
-
|
168
|
+
return dependencies
|
142
169
|
.filter(dependency => dependency.module)
|
143
170
|
.sort((a, b) => {
|
144
171
|
if(a.userRequest === b.userRequest) {
|
@@ -149,6 +176,10 @@ class ContextModule extends Module {
|
|
149
176
|
map[dep.userRequest] = dep.module.id;
|
150
177
|
return map;
|
151
178
|
}, Object.create(null));
|
179
|
+
}
|
180
|
+
|
181
|
+
getSyncSource(dependencies, id) {
|
182
|
+
const map = this.getUserRequestMap(dependencies);
|
152
183
|
return `var map = ${JSON.stringify(map, null, "\t")};
|
153
184
|
function webpackContext(req) {
|
154
185
|
return __webpack_require__(webpackContextResolve(req));
|
@@ -167,7 +198,53 @@ module.exports = webpackContext;
|
|
167
198
|
webpackContext.id = ${JSON.stringify(id)};`;
|
168
199
|
}
|
169
200
|
|
170
|
-
|
201
|
+
getEagerSource(dependencies, id) {
|
202
|
+
const map = this.getUserRequestMap(dependencies);
|
203
|
+
return `var map = ${JSON.stringify(map, null, "\t")};
|
204
|
+
function webpackAsyncContext(req) {
|
205
|
+
return webpackAsyncContextResolve(req).then(__webpack_require__);
|
206
|
+
};
|
207
|
+
function webpackAsyncContextResolve(req) {
|
208
|
+
return new Promise(function(resolve, reject) {
|
209
|
+
var id = map[req];
|
210
|
+
if(!(id + 1)) // check for number or string
|
211
|
+
reject(new Error("Cannot find module '" + req + "'."));
|
212
|
+
else
|
213
|
+
resolve(id);
|
214
|
+
});
|
215
|
+
};
|
216
|
+
webpackAsyncContext.keys = function webpackAsyncContextKeys() {
|
217
|
+
return Object.keys(map);
|
218
|
+
};
|
219
|
+
webpackAsyncContext.resolve = webpackAsyncContextResolve;
|
220
|
+
module.exports = webpackAsyncContext;
|
221
|
+
webpackAsyncContext.id = ${JSON.stringify(id)};`;
|
222
|
+
}
|
223
|
+
|
224
|
+
getLazyOnceSource(block, dependencies, id, outputOptions, requestShortener) {
|
225
|
+
const promise = DepBlockHelpers.getDepBlockPromise(block, outputOptions, requestShortener, "lazy-once context");
|
226
|
+
const map = this.getUserRequestMap(dependencies);
|
227
|
+
return `var map = ${JSON.stringify(map, null, "\t")};
|
228
|
+
function webpackAsyncContext(req) {
|
229
|
+
return webpackAsyncContextResolve(req).then(__webpack_require__);
|
230
|
+
};
|
231
|
+
function webpackAsyncContextResolve(req) {
|
232
|
+
return ${promise}.then(function() {
|
233
|
+
var id = map[req];
|
234
|
+
if(!(id + 1)) // check for number or string
|
235
|
+
throw new Error("Cannot find module '" + req + "'.");
|
236
|
+
return id;
|
237
|
+
});
|
238
|
+
};
|
239
|
+
webpackAsyncContext.keys = function webpackAsyncContextKeys() {
|
240
|
+
return Object.keys(map);
|
241
|
+
};
|
242
|
+
webpackAsyncContext.resolve = webpackAsyncContextResolve;
|
243
|
+
module.exports = webpackAsyncContext;
|
244
|
+
webpackAsyncContext.id = ${JSON.stringify(id)};`;
|
245
|
+
}
|
246
|
+
|
247
|
+
getLazySource(blocks, id) {
|
171
248
|
let hasMultipleOrNoChunks = false;
|
172
249
|
const map = blocks
|
173
250
|
.filter(block => block.dependencies[0].module)
|
@@ -219,15 +296,38 @@ module.exports = webpackEmptyContext;
|
|
219
296
|
webpackEmptyContext.id = ${JSON.stringify(id)};`;
|
220
297
|
}
|
221
298
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
299
|
+
getSourceForEmptyAsyncContext(id) {
|
300
|
+
return `function webpackEmptyAsyncContext(req) {
|
301
|
+
return new Promise(function(resolve, reject) { reject(new Error("Cannot find module '" + req + "'.")); });
|
302
|
+
}
|
303
|
+
webpackEmptyAsyncContext.keys = function() { return []; };
|
304
|
+
webpackEmptyAsyncContext.resolve = webpackEmptyAsyncContext;
|
305
|
+
module.exports = webpackEmptyAsyncContext;
|
306
|
+
webpackEmptyAsyncContext.id = ${JSON.stringify(id)};`;
|
307
|
+
}
|
226
308
|
|
227
|
-
|
228
|
-
|
309
|
+
getSourceString(asyncMode, outputOptions, requestShortener) {
|
310
|
+
if(asyncMode === "lazy") {
|
311
|
+
if(this.blocks && this.blocks.length > 0) {
|
312
|
+
return this.getLazySource(this.blocks, this.id);
|
313
|
+
}
|
314
|
+
return this.getSourceForEmptyAsyncContext(this.id);
|
315
|
+
}
|
316
|
+
if(asyncMode === "eager") {
|
317
|
+
if(this.dependencies && this.dependencies.length > 0) {
|
318
|
+
return this.getEagerSource(this.dependencies, this.id);
|
319
|
+
}
|
320
|
+
return this.getSourceForEmptyAsyncContext(this.id);
|
321
|
+
} else if(asyncMode === "lazy-once") {
|
322
|
+
const block = this.blocks[0];
|
323
|
+
if(block) {
|
324
|
+
return this.getLazyOnceSource(block, block.dependencies, this.id, outputOptions, requestShortener);
|
325
|
+
}
|
326
|
+
return this.getSourceForEmptyAsyncContext(this.id);
|
327
|
+
}
|
328
|
+
if(this.dependencies && this.dependencies.length > 0) {
|
329
|
+
return this.getSyncSource(this.dependencies, this.id);
|
229
330
|
}
|
230
|
-
|
231
331
|
return this.getSourceForEmptyContext(this.id);
|
232
332
|
}
|
233
333
|
|
@@ -238,9 +338,9 @@ webpackEmptyContext.id = ${JSON.stringify(id)};`;
|
|
238
338
|
return new RawSource(sourceString);
|
239
339
|
}
|
240
340
|
|
241
|
-
source() {
|
341
|
+
source(dependencyTemplates, outputOptions, requestShortener) {
|
242
342
|
return this.getSource(
|
243
|
-
this.getSourceString()
|
343
|
+
this.getSourceString(this.async, outputOptions, requestShortener)
|
244
344
|
);
|
245
345
|
}
|
246
346
|
|
package/lib/DelegatedModule.js
CHANGED
@@ -37,7 +37,7 @@ class DelegatedModule extends Module {
|
|
37
37
|
|
38
38
|
build(options, compilation, resolver, fs, callback) {
|
39
39
|
this.built = true;
|
40
|
-
this.builtTime =
|
40
|
+
this.builtTime = Date.now();
|
41
41
|
this.usedExports = true;
|
42
42
|
this.providedExports = this.delegateData.exports || true;
|
43
43
|
this.dependencies.length = 0;
|
@@ -67,6 +67,8 @@ class DelegatedModule extends Module {
|
|
67
67
|
str += `[${JSON.stringify(this.request)}]`;
|
68
68
|
break;
|
69
69
|
}
|
70
|
+
|
71
|
+
str += ";";
|
70
72
|
}
|
71
73
|
|
72
74
|
if(this.useSourceMap) {
|
package/lib/ExternalModule.js
CHANGED
@@ -28,7 +28,7 @@ class FunctionModuleTemplatePlugin {
|
|
28
28
|
if(Array.isArray(module.providedExports))
|
29
29
|
source.add("/* exports provided: " + module.providedExports.join(", ") + " */\n");
|
30
30
|
else if(module.providedExports)
|
31
|
-
source.add("/*
|
31
|
+
source.add("/* no static exports found */\n");
|
32
32
|
if(Array.isArray(module.usedExports))
|
33
33
|
source.add("/* exports used: " + module.usedExports.join(", ") + " */\n");
|
34
34
|
else if(module.usedExports)
|
package/lib/IgnorePlugin.js
CHANGED
@@ -16,7 +16,7 @@ class IgnorePlugin {
|
|
16
16
|
* Only returns true if a "resourceRegExp" exists
|
17
17
|
* and the resource given matches the regexp.
|
18
18
|
*/
|
19
|
-
|
19
|
+
checkResource(resource) {
|
20
20
|
if(!this.resourceRegExp) {
|
21
21
|
return false;
|
22
22
|
}
|
@@ -45,7 +45,7 @@ class IgnorePlugin {
|
|
45
45
|
if(!result) {
|
46
46
|
return true;
|
47
47
|
}
|
48
|
-
return this.
|
48
|
+
return this.checkResource(result.request) && this.checkContext(result.context);
|
49
49
|
}
|
50
50
|
|
51
51
|
checkIgnore(result, callback) {
|