webpack 2.5.0 → 2.7.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/lib/Compiler.js +1 -1
- package/lib/ContextModule.js +132 -32
- package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +4 -3
- package/lib/FunctionModuleTemplatePlugin.js +1 -1
- package/lib/HotModuleReplacement.runtime.js +3 -1
- package/lib/JsonpMainTemplatePlugin.js +8 -7
- package/lib/Parser.js +33 -20
- package/lib/SourceMapDevToolPlugin.js +9 -4
- package/lib/Template.js +5 -0
- 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/node/NodeSourcePlugin.js +72 -70
- package/lib/webworker/WebWorkerMainTemplatePlugin.js +18 -14
- package/package.json +10 -10
- package/schemas/webpackOptionsSchema.json +7 -0
package/lib/Compiler.js
CHANGED
@@ -88,7 +88,7 @@ Watching.prototype._done = function(err, compilation) {
|
|
88
88
|
this.running = false;
|
89
89
|
if(this.invalid) return this._go();
|
90
90
|
|
91
|
-
var stats = this._getStats(compilation);
|
91
|
+
var stats = compilation ? this._getStats(compilation) : null;
|
92
92
|
if(err) {
|
93
93
|
this.compiler.applyPlugins("failed", err);
|
94
94
|
this.handler(err, stats);
|
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)
|
@@ -103,42 +105,67 @@ class ContextModule extends Module {
|
|
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
|
|
@@ -10,7 +10,7 @@ const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
|
10
10
|
class EvalSourceMapDevToolModuleTemplatePlugin {
|
11
11
|
constructor(compilation, options) {
|
12
12
|
this.compilation = compilation;
|
13
|
-
this.sourceMapComment = options.append || "//# sourceMappingURL=[url]";
|
13
|
+
this.sourceMapComment = options.append || "//# sourceURL=[module]\n//# sourceMappingURL=[url]";
|
14
14
|
this.moduleFilenameTemplate = options.moduleFilenameTemplate || "webpack:///[resource-path]?[hash]";
|
15
15
|
this.options = options;
|
16
16
|
}
|
@@ -61,13 +61,14 @@ class EvalSourceMapDevToolModuleTemplatePlugin {
|
|
61
61
|
sourceMap.sourceRoot = options.sourceRoot || "";
|
62
62
|
sourceMap.file = `${module.id}.js`;
|
63
63
|
|
64
|
-
const footer = self.sourceMapComment.replace(/\[url\]/g, `data:application/json;charset=utf-8;base64,${new Buffer(JSON.stringify(sourceMap), "utf8").toString("base64")}`)
|
64
|
+
const footer = self.sourceMapComment.replace(/\[url\]/g, `data:application/json;charset=utf-8;base64,${new Buffer(JSON.stringify(sourceMap), "utf8").toString("base64")}`) + //eslint-disable-line
|
65
|
+
`\n//# sourceURL=webpack-internal:///${module.id}\n`; // workaround for chrome bug
|
65
66
|
source.__EvalSourceMapDevToolData = new RawSource(`eval(${JSON.stringify(content + footer)});`);
|
66
67
|
return source.__EvalSourceMapDevToolData;
|
67
68
|
});
|
68
69
|
moduleTemplate.plugin("hash", function(hash) {
|
69
70
|
hash.update("eval-source-map");
|
70
|
-
hash.update("
|
71
|
+
hash.update("2");
|
71
72
|
});
|
72
73
|
}
|
73
74
|
}
|
@@ -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)
|
@@ -28,7 +28,7 @@ class JsonpMainTemplatePlugin {
|
|
28
28
|
const chunkFilename = this.outputOptions.chunkFilename;
|
29
29
|
const chunkMaps = chunk.getChunkMaps();
|
30
30
|
const crossOriginLoading = this.outputOptions.crossOriginLoading;
|
31
|
-
const chunkLoadTimeout = this.outputOptions.chunkLoadTimeout
|
31
|
+
const chunkLoadTimeout = this.outputOptions.chunkLoadTimeout;
|
32
32
|
const scriptSrcPath = this.applyPluginsWaterfall("asset-path", JSON.stringify(chunkFilename), {
|
33
33
|
hash: `" + ${this.renderCurrentHashCode(hash)} + "`,
|
34
34
|
hashWithLength: length => `" + ${this.renderCurrentHashCode(hash, length)} + "`,
|
@@ -79,26 +79,27 @@ class JsonpMainTemplatePlugin {
|
|
79
79
|
});
|
80
80
|
mainTemplate.plugin("require-ensure", function(_, chunk, hash) {
|
81
81
|
return this.asString([
|
82
|
-
"
|
82
|
+
"var installedChunkData = installedChunks[chunkId];",
|
83
|
+
"if(installedChunkData === 0) {",
|
83
84
|
this.indent([
|
84
|
-
"return Promise
|
85
|
+
"return new Promise(function(resolve) { resolve(); });"
|
85
86
|
]),
|
86
87
|
"}",
|
87
88
|
"",
|
88
89
|
"// a Promise means \"currently loading\".",
|
89
|
-
"if(
|
90
|
+
"if(installedChunkData) {",
|
90
91
|
this.indent([
|
91
|
-
"return
|
92
|
+
"return installedChunkData[2];"
|
92
93
|
]),
|
93
94
|
"}",
|
94
95
|
"",
|
95
96
|
"// setup Promise in chunk cache",
|
96
97
|
"var promise = new Promise(function(resolve, reject) {",
|
97
98
|
this.indent([
|
98
|
-
"installedChunks[chunkId] = [resolve, reject];"
|
99
|
+
"installedChunkData = installedChunks[chunkId] = [resolve, reject];"
|
99
100
|
]),
|
100
101
|
"});",
|
101
|
-
"
|
102
|
+
"installedChunkData[2] = promise;",
|
102
103
|
"",
|
103
104
|
"// start chunk loading",
|
104
105
|
"var head = document.getElementsByTagName('head')[0];",
|
package/lib/Parser.js
CHANGED
@@ -636,6 +636,9 @@ class Parser extends Tapable {
|
|
636
636
|
}
|
637
637
|
|
638
638
|
walkFunctionDeclaration(statement) {
|
639
|
+
statement.params.forEach(param => {
|
640
|
+
this.walkPattern(param);
|
641
|
+
});
|
639
642
|
this.inScope(statement.params, function() {
|
640
643
|
if(statement.body.type === "BlockStatement") {
|
641
644
|
this.prewalkStatement(statement.body);
|
@@ -797,24 +800,15 @@ class Parser extends Tapable {
|
|
797
800
|
switch(declarator.type) {
|
798
801
|
case "VariableDeclarator":
|
799
802
|
{
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
const idx = this.scope.definitions.indexOf(declarator.id.name);
|
806
|
-
if(idx >= 0) this.scope.definitions.splice(idx, 1);
|
807
|
-
}
|
808
|
-
} else {
|
809
|
-
this.enterPattern(declarator.id, (name, decl) => {
|
810
|
-
if(!this.applyPluginsBailResult1("var-" + declarator.kind + " " + name, decl)) {
|
811
|
-
if(!this.applyPluginsBailResult1("var " + name, decl)) {
|
812
|
-
this.scope.renames["$" + name] = undefined;
|
803
|
+
this.enterPattern(declarator.id, (name, decl) => {
|
804
|
+
if(!this.applyPluginsBailResult1("var-" + declarator.kind + " " + name, decl)) {
|
805
|
+
if(!this.applyPluginsBailResult1("var " + name, decl)) {
|
806
|
+
this.scope.renames["$" + name] = undefined;
|
807
|
+
if(this.scope.definitions.indexOf(name) < 0)
|
813
808
|
this.scope.definitions.push(name);
|
814
|
-
}
|
815
809
|
}
|
816
|
-
}
|
817
|
-
}
|
810
|
+
}
|
811
|
+
});
|
818
812
|
break;
|
819
813
|
}
|
820
814
|
}
|
@@ -827,7 +821,14 @@ class Parser extends Tapable {
|
|
827
821
|
case "VariableDeclarator":
|
828
822
|
{
|
829
823
|
const renameIdentifier = declarator.init && this.getRenameIdentifier(declarator.init);
|
830
|
-
if(
|
824
|
+
if(renameIdentifier && declarator.id.type === "Identifier" && this.applyPluginsBailResult1("can-rename " + renameIdentifier, declarator.init)) {
|
825
|
+
// renaming with "var a = b;"
|
826
|
+
if(!this.applyPluginsBailResult1("rename " + renameIdentifier, declarator.init)) {
|
827
|
+
this.scope.renames["$" + declarator.id.name] = this.scope.renames["$" + renameIdentifier] || renameIdentifier;
|
828
|
+
const idx = this.scope.definitions.indexOf(declarator.id.name);
|
829
|
+
if(idx >= 0) this.scope.definitions.splice(idx, 1);
|
830
|
+
}
|
831
|
+
} else {
|
831
832
|
this.walkPattern(declarator.id);
|
832
833
|
if(declarator.init)
|
833
834
|
this.walkExpression(declarator.init);
|
@@ -845,6 +846,11 @@ class Parser extends Tapable {
|
|
845
846
|
this["walk" + pattern.type](pattern);
|
846
847
|
}
|
847
848
|
|
849
|
+
walkAssignmentPattern(pattern) {
|
850
|
+
this.walkExpression(pattern.right);
|
851
|
+
this.walkPattern(pattern.left);
|
852
|
+
}
|
853
|
+
|
848
854
|
walkObjectPattern(pattern) {
|
849
855
|
for(let i = 0, len = pattern.properties.length; i < len; i++) {
|
850
856
|
const prop = pattern.properties[i];
|
@@ -912,6 +918,9 @@ class Parser extends Tapable {
|
|
912
918
|
}
|
913
919
|
|
914
920
|
walkFunctionExpression(expression) {
|
921
|
+
expression.params.forEach(param => {
|
922
|
+
this.walkPattern(param);
|
923
|
+
});
|
915
924
|
this.inScope(expression.params, function() {
|
916
925
|
if(expression.body.type === "BlockStatement") {
|
917
926
|
this.prewalkStatement(expression.body);
|
@@ -923,6 +932,9 @@ class Parser extends Tapable {
|
|
923
932
|
}
|
924
933
|
|
925
934
|
walkArrowFunctionExpression(expression) {
|
935
|
+
expression.params.forEach(param => {
|
936
|
+
this.walkPattern(param);
|
937
|
+
});
|
926
938
|
this.inScope(expression.params, function() {
|
927
939
|
if(expression.body.type === "BlockStatement") {
|
928
940
|
this.prewalkStatement(expression.body);
|
@@ -993,8 +1005,10 @@ class Parser extends Tapable {
|
|
993
1005
|
}
|
994
1006
|
} else {
|
995
1007
|
this.walkExpression(expression.right);
|
996
|
-
this.
|
997
|
-
this.
|
1008
|
+
this.walkPattern(expression.left);
|
1009
|
+
this.enterPattern(expression.left, (name, decl) => {
|
1010
|
+
this.scope.renames["$" + name] = undefined;
|
1011
|
+
});
|
998
1012
|
}
|
999
1013
|
}
|
1000
1014
|
|
@@ -1191,7 +1205,6 @@ class Parser extends Tapable {
|
|
1191
1205
|
|
1192
1206
|
enterAssignmentPattern(pattern, onIdent) {
|
1193
1207
|
this.enterPattern(pattern.left, onIdent);
|
1194
|
-
this.walkExpression(pattern.right);
|
1195
1208
|
}
|
1196
1209
|
|
1197
1210
|
evaluateExpression(expression) {
|
@@ -5,6 +5,7 @@
|
|
5
5
|
"use strict";
|
6
6
|
|
7
7
|
const path = require("path");
|
8
|
+
const crypto = require("crypto");
|
8
9
|
const RequestShortener = require("./RequestShortener");
|
9
10
|
const ConcatSource = require("webpack-sources").ConcatSource;
|
10
11
|
const RawSource = require("webpack-sources").RawSource;
|
@@ -131,6 +132,7 @@ class SourceMapDevToolPlugin {
|
|
131
132
|
if(currentSourceMappingURLComment !== false && /\.css($|\?)/i.test(file)) {
|
132
133
|
currentSourceMappingURLComment = currentSourceMappingURLComment.replace(/^\n\/\/(.*)$/, "\n/*$1*/");
|
133
134
|
}
|
135
|
+
const sourceMapString = JSON.stringify(sourceMap);
|
134
136
|
if(sourceMapFilename) {
|
135
137
|
let filename = file;
|
136
138
|
let query = "";
|
@@ -139,22 +141,25 @@ class SourceMapDevToolPlugin {
|
|
139
141
|
query = filename.substr(idx);
|
140
142
|
filename = filename.substr(0, idx);
|
141
143
|
}
|
142
|
-
|
144
|
+
let sourceMapFile = compilation.getPath(sourceMapFilename, {
|
143
145
|
chunk,
|
144
146
|
filename,
|
145
147
|
query,
|
146
148
|
basename: basename(filename)
|
147
149
|
});
|
150
|
+
if(sourceMapFile.indexOf("[contenthash]") !== -1) {
|
151
|
+
sourceMapFile = sourceMapFile.replace(/\[contenthash\]/g, crypto.createHash("md5").update(sourceMapString).digest("hex"));
|
152
|
+
}
|
148
153
|
const sourceMapUrl = path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/");
|
149
154
|
if(currentSourceMappingURLComment !== false) {
|
150
155
|
asset.__SourceMapDevToolData[file] = compilation.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment.replace(/\[url\]/g, sourceMapUrl));
|
151
156
|
}
|
152
|
-
asset.__SourceMapDevToolData[sourceMapFile] = compilation.assets[sourceMapFile] = new RawSource(
|
157
|
+
asset.__SourceMapDevToolData[sourceMapFile] = compilation.assets[sourceMapFile] = new RawSource(sourceMapString);
|
153
158
|
chunk.files.push(sourceMapFile);
|
154
159
|
} else {
|
155
160
|
asset.__SourceMapDevToolData[file] = compilation.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment
|
156
|
-
.replace(/\[map\]/g, () =>
|
157
|
-
.replace(/\[url\]/g, () => `data:application/json;charset=utf-8;base64,${new Buffer(
|
161
|
+
.replace(/\[map\]/g, () => sourceMapString)
|
162
|
+
.replace(/\[url\]/g, () => `data:application/json;charset=utf-8;base64,${new Buffer(sourceMapString, "utf-8").toString("base64")}`) // eslint-disable-line
|
158
163
|
);
|
159
164
|
}
|
160
165
|
});
|
package/lib/Template.js
CHANGED
@@ -26,6 +26,11 @@ module.exports = class Template extends Tapable {
|
|
26
26
|
return str.replace(/^[^a-zA-Z$_]/, "_").replace(/[^a-zA-Z0-9$_]/g, "_");
|
27
27
|
}
|
28
28
|
|
29
|
+
static toPath(str) {
|
30
|
+
if(typeof str !== "string") return "";
|
31
|
+
return str.replace(/[^a-zA-Z0-9_!§$()=\-\^°]+/g, "-").replace(/^-|-$/, "");
|
32
|
+
}
|
33
|
+
|
29
34
|
// map number to a single character a-z, A-Z or <_ + number> if number is too big
|
30
35
|
static numberToIdentifer(n) {
|
31
36
|
// lower case
|
@@ -60,6 +60,7 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
|
|
60
60
|
this.set("output.hotUpdateChunkFilename", "[id].[hash].hot-update.js");
|
61
61
|
this.set("output.hotUpdateMainFilename", "[hash].hot-update.json");
|
62
62
|
this.set("output.crossOriginLoading", false);
|
63
|
+
this.set("output.chunkLoadTimeout", 120000);
|
63
64
|
this.set("output.hashFunction", "md5");
|
64
65
|
this.set("output.hashDigest", "hex");
|
65
66
|
this.set("output.hashDigestLength", 20);
|
@@ -22,7 +22,7 @@ HarmonyCompatibilityDependency.Template = class HarmonyExportDependencyTemplate
|
|
22
22
|
if(usedExports && !Array.isArray(usedExports)) {
|
23
23
|
const exportName = dep.originModule.exportsArgument || "exports";
|
24
24
|
const content = `Object.defineProperty(${exportName}, \"__esModule\", { value: true });\n`;
|
25
|
-
source.insert(-
|
25
|
+
source.insert(-10, content);
|
26
26
|
}
|
27
27
|
}
|
28
28
|
};
|
@@ -45,7 +45,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
45
45
|
} else {
|
46
46
|
const immutable = statement.declaration && isImmutableStatement(statement.declaration);
|
47
47
|
const hoisted = statement.declaration && isHoistedStatement(statement.declaration);
|
48
|
-
dep = new HarmonyExportSpecifierDependency(parser.state.module, id, name, !immutable || hoisted ? -
|
48
|
+
dep = new HarmonyExportSpecifierDependency(parser.state.module, id, name, !immutable || hoisted ? -2 : (statement.range[1] + 0.5), immutable);
|
49
49
|
}
|
50
50
|
dep.loc = Object.create(statement.loc);
|
51
51
|
dep.loc.index = idx;
|
@@ -44,7 +44,7 @@ ImportDependency.Template = class ImportDependencyTemplate {
|
|
44
44
|
|
45
45
|
if(dep.module) {
|
46
46
|
const stringifiedId = JSON.stringify(dep.module.id);
|
47
|
-
return `Promise
|
47
|
+
return `new Promise(function(resolve) { resolve(__webpack_require__(${comment}${stringifiedId})); })`;
|
48
48
|
}
|
49
49
|
|
50
50
|
return webpackMissingPromiseModule(dep.request);
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
const ImportContextDependency = require("./ImportContextDependency");
|
7
|
+
const ContextDependencyTemplateAsRequireCall = require("./ContextDependencyTemplateAsRequireCall");
|
8
|
+
|
9
|
+
class ImportEagerContextDependency extends ImportContextDependency {
|
10
|
+
constructor(request, recursive, regExp, range, valueRange, chunkName) {
|
11
|
+
super(request, recursive, regExp, range, valueRange, chunkName);
|
12
|
+
this.async = "eager";
|
13
|
+
}
|
14
|
+
|
15
|
+
get type() {
|
16
|
+
return "import() context eager";
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
ImportEagerContextDependency.Template = ContextDependencyTemplateAsRequireCall;
|
21
|
+
|
22
|
+
module.exports = ImportEagerContextDependency;
|
@@ -0,0 +1,46 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
const ModuleDependency = require("./ModuleDependency");
|
7
|
+
const webpackMissingPromiseModule = require("./WebpackMissingModule").promise;
|
8
|
+
|
9
|
+
class ImportEagerDependency extends ModuleDependency {
|
10
|
+
constructor(request, range) {
|
11
|
+
super(request);
|
12
|
+
this.range = range;
|
13
|
+
}
|
14
|
+
|
15
|
+
get type() {
|
16
|
+
return "import()";
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
ImportEagerDependency.Template = class ImportEagerDependencyTemplate {
|
21
|
+
apply(dep, source, outputOptions, requestShortener) {
|
22
|
+
const comment = this.getOptionalComment(outputOptions.pathinfo, requestShortener.shorten(dep.request));
|
23
|
+
|
24
|
+
const content = this.getContent(dep, comment);
|
25
|
+
source.replace(dep.range[0], dep.range[1] - 1, content);
|
26
|
+
}
|
27
|
+
|
28
|
+
getOptionalComment(pathinfo, shortenedRequest) {
|
29
|
+
if(!pathinfo) {
|
30
|
+
return "";
|
31
|
+
}
|
32
|
+
|
33
|
+
return `/*! ${shortenedRequest} */ `;
|
34
|
+
}
|
35
|
+
|
36
|
+
getContent(dep, comment) {
|
37
|
+
if(dep.module) {
|
38
|
+
const stringifiedId = JSON.stringify(dep.module.id);
|
39
|
+
return `new Promise(function(resolve) { resolve(__webpack_require__(${comment}${stringifiedId})); })`;
|
40
|
+
}
|
41
|
+
|
42
|
+
return webpackMissingPromiseModule(dep.request);
|
43
|
+
}
|
44
|
+
};
|
45
|
+
|
46
|
+
module.exports = ImportEagerDependency;
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
const ImportContextDependency = require("./ImportContextDependency");
|
7
|
+
const ContextDependencyTemplateAsRequireCall = require("./ContextDependencyTemplateAsRequireCall");
|
8
|
+
|
9
|
+
class ImportLazyContextDependency extends ImportContextDependency {
|
10
|
+
constructor(request, recursive, regExp, range, valueRange, chunkName) {
|
11
|
+
super(request, recursive, regExp, range, valueRange, chunkName);
|
12
|
+
this.async = "lazy";
|
13
|
+
}
|
14
|
+
|
15
|
+
get type() {
|
16
|
+
return "import() context lazy";
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
ImportLazyContextDependency.Template = ContextDependencyTemplateAsRequireCall;
|
21
|
+
|
22
|
+
module.exports = ImportLazyContextDependency;
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
const ImportContextDependency = require("./ImportContextDependency");
|
7
|
+
const ContextDependencyTemplateAsRequireCall = require("./ContextDependencyTemplateAsRequireCall");
|
8
|
+
|
9
|
+
class ImportLazyOnceContextDependency extends ImportContextDependency {
|
10
|
+
constructor(request, recursive, regExp, range, valueRange, chunkName) {
|
11
|
+
super(request, recursive, regExp, range, valueRange, chunkName);
|
12
|
+
this.async = "lazy-once";
|
13
|
+
}
|
14
|
+
|
15
|
+
get type() {
|
16
|
+
return "import() context lazy-once";
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
ImportLazyOnceContextDependency.Template = ContextDependencyTemplateAsRequireCall;
|
21
|
+
|
22
|
+
module.exports = ImportLazyOnceContextDependency;
|
@@ -4,9 +4,13 @@
|
|
4
4
|
*/
|
5
5
|
"use strict";
|
6
6
|
|
7
|
-
const
|
7
|
+
const ImportEagerContextDependency = require("./ImportEagerContextDependency");
|
8
|
+
const ImportLazyOnceContextDependency = require("./ImportLazyOnceContextDependency");
|
9
|
+
const ImportLazyContextDependency = require("./ImportLazyContextDependency");
|
8
10
|
const ImportDependenciesBlock = require("./ImportDependenciesBlock");
|
11
|
+
const ImportEagerDependency = require("./ImportEagerDependency");
|
9
12
|
const ContextDependencyHelpers = require("./ContextDependencyHelpers");
|
13
|
+
const UnsupportedFeatureWarning = require("../UnsupportedFeatureWarning");
|
10
14
|
|
11
15
|
class ImportParserPlugin {
|
12
16
|
constructor(options) {
|
@@ -23,22 +27,49 @@ class ImportParserPlugin {
|
|
23
27
|
const param = parser.evaluateExpression(expr.arguments[0]);
|
24
28
|
|
25
29
|
let chunkName = null;
|
30
|
+
let mode = "lazy";
|
26
31
|
|
27
32
|
const importOptions = parser.getCommentOptions(expr.range);
|
28
33
|
if(importOptions) {
|
29
34
|
if(typeof importOptions.webpackChunkName !== "undefined") {
|
30
35
|
if(typeof importOptions.webpackChunkName !== "string")
|
31
|
-
|
32
|
-
|
36
|
+
parser.state.module.warnings.push(new UnsupportedFeatureWarning(parser.state.module, `\`webpackChunkName\` expected a string, but received: ${importOptions.webpackChunkName}.`));
|
37
|
+
else
|
38
|
+
chunkName = importOptions.webpackChunkName;
|
39
|
+
}
|
40
|
+
if(typeof importOptions.webpackMode !== "undefined") {
|
41
|
+
if(typeof importOptions.webpackMode !== "string")
|
42
|
+
parser.state.module.warnings.push(new UnsupportedFeatureWarning(parser.state.module, `\`webpackMode\` expected a string, but received: ${importOptions.webpackMode}.`));
|
43
|
+
else
|
44
|
+
mode = importOptions.webpackMode;
|
33
45
|
}
|
34
46
|
}
|
35
47
|
|
36
48
|
if(param.isString()) {
|
37
|
-
|
38
|
-
|
49
|
+
if(mode !== "lazy" && mode !== "eager") {
|
50
|
+
parser.state.module.warnings.push(new UnsupportedFeatureWarning(parser.state.module, `\`webpackMode\` expected 'lazy' or 'eager', but received: ${mode}.`));
|
51
|
+
}
|
52
|
+
|
53
|
+
if(mode === "eager") {
|
54
|
+
const dep = new ImportEagerDependency(param.string, expr.range);
|
55
|
+
parser.state.current.addDependency(dep);
|
56
|
+
} else {
|
57
|
+
const depBlock = new ImportDependenciesBlock(param.string, expr.range, chunkName, parser.state.module, expr.loc);
|
58
|
+
parser.state.current.addBlock(depBlock);
|
59
|
+
}
|
39
60
|
return true;
|
40
61
|
} else {
|
41
|
-
|
62
|
+
if(mode !== "lazy" && mode !== "lazy-once" && mode !== "eager") {
|
63
|
+
parser.state.module.warnings.push(new UnsupportedFeatureWarning(parser.state.module, `\`webpackMode\` expected 'lazy', 'lazy-once' or 'eager', but received: ${mode}.`));
|
64
|
+
}
|
65
|
+
|
66
|
+
let Dep = ImportLazyContextDependency;
|
67
|
+
if(mode === "eager") {
|
68
|
+
Dep = ImportEagerContextDependency;
|
69
|
+
} else if(mode === "lazy-once") {
|
70
|
+
Dep = ImportLazyOnceContextDependency;
|
71
|
+
}
|
72
|
+
const dep = ContextDependencyHelpers.create(Dep, expr.range, param, expr, options, chunkName);
|
42
73
|
if(!dep) return;
|
43
74
|
dep.loc = expr.loc;
|
44
75
|
dep.optional = !!parser.scope.inTry;
|
@@ -5,7 +5,10 @@
|
|
5
5
|
"use strict";
|
6
6
|
|
7
7
|
const ImportDependency = require("./ImportDependency");
|
8
|
-
const
|
8
|
+
const ImportEagerDependency = require("./ImportEagerDependency");
|
9
|
+
const ImportEagerContextDependency = require("./ImportEagerContextDependency");
|
10
|
+
const ImportLazyOnceContextDependency = require("./ImportLazyOnceContextDependency");
|
11
|
+
const ImportLazyContextDependency = require("./ImportLazyContextDependency");
|
9
12
|
const ImportParserPlugin = require("./ImportParserPlugin");
|
10
13
|
|
11
14
|
class ImportPlugin {
|
@@ -22,8 +25,17 @@ class ImportPlugin {
|
|
22
25
|
compilation.dependencyFactories.set(ImportDependency, normalModuleFactory);
|
23
26
|
compilation.dependencyTemplates.set(ImportDependency, new ImportDependency.Template());
|
24
27
|
|
25
|
-
compilation.dependencyFactories.set(
|
26
|
-
compilation.dependencyTemplates.set(
|
28
|
+
compilation.dependencyFactories.set(ImportEagerDependency, normalModuleFactory);
|
29
|
+
compilation.dependencyTemplates.set(ImportEagerDependency, new ImportEagerDependency.Template());
|
30
|
+
|
31
|
+
compilation.dependencyFactories.set(ImportEagerContextDependency, contextModuleFactory);
|
32
|
+
compilation.dependencyTemplates.set(ImportEagerContextDependency, new ImportEagerContextDependency.Template());
|
33
|
+
|
34
|
+
compilation.dependencyFactories.set(ImportLazyOnceContextDependency, contextModuleFactory);
|
35
|
+
compilation.dependencyTemplates.set(ImportLazyOnceContextDependency, new ImportLazyOnceContextDependency.Template());
|
36
|
+
|
37
|
+
compilation.dependencyFactories.set(ImportLazyContextDependency, contextModuleFactory);
|
38
|
+
compilation.dependencyTemplates.set(ImportLazyContextDependency, new ImportLazyContextDependency.Template());
|
27
39
|
|
28
40
|
params.normalModuleFactory.plugin("parser", (parser, parserOptions) => {
|
29
41
|
|
@@ -11,14 +11,8 @@ module.exports = class RequireEnsureDependenciesBlock extends AsyncDependenciesB
|
|
11
11
|
super(chunkName, module, loc);
|
12
12
|
this.expr = expr;
|
13
13
|
const successBodyRange = successExpression && successExpression.body && successExpression.body.range;
|
14
|
-
const errorBodyRange = errorExpression && errorExpression.body && errorExpression.body.range;
|
15
|
-
this.range = null;
|
16
14
|
if(successBodyRange) {
|
17
|
-
|
18
|
-
this.range = [successBodyRange[0] + 1, errorBodyRange[1] - 1];
|
19
|
-
} else {
|
20
|
-
this.range = [successBodyRange[0] + 1, successBodyRange[1] - 1];
|
21
|
-
}
|
15
|
+
this.range = [successBodyRange[0] + 1, successBodyRange[1] - 1];
|
22
16
|
}
|
23
17
|
this.chunkNameRange = chunkNameRange;
|
24
18
|
const dep = new RequireEnsureDependency(this);
|
@@ -2,83 +2,85 @@
|
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
"use strict";
|
6
|
+
const AliasPlugin = require("enhanced-resolve/lib/AliasPlugin");
|
7
|
+
const ParserHelpers = require("../ParserHelpers");
|
8
|
+
const nodeLibsBrowser = require("node-libs-browser");
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
module.exports = NodeSourcePlugin;
|
13
|
-
NodeSourcePlugin.prototype.apply = function(compiler) {
|
14
|
-
var options = this.options;
|
15
|
-
|
16
|
-
function getPathToModule(module, type) {
|
17
|
-
if(type === true || (type === undefined && nodeLibsBrowser[module])) {
|
18
|
-
if(!nodeLibsBrowser[module]) throw new Error("No browser version for node.js core module '" + module + "' available");
|
19
|
-
return nodeLibsBrowser[module];
|
20
|
-
} else if(type === "mock") {
|
21
|
-
return require.resolve("node-libs-browser/mock/" + module);
|
22
|
-
} else if(type === "empty") {
|
23
|
-
return require.resolve("node-libs-browser/mock/empty");
|
24
|
-
} else return module;
|
10
|
+
module.exports = class NodeSourcePlugin {
|
11
|
+
constructor(options) {
|
12
|
+
this.options = options;
|
25
13
|
}
|
14
|
+
apply(compiler) {
|
15
|
+
const options = this.options;
|
26
16
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
17
|
+
function getPathToModule(module, type) {
|
18
|
+
if(type === true || (type === undefined && nodeLibsBrowser[module])) {
|
19
|
+
if(!nodeLibsBrowser[module]) throw new Error(`No browser version for node.js core module ${module} available`);
|
20
|
+
return nodeLibsBrowser[module];
|
21
|
+
} else if(type === "mock") {
|
22
|
+
return require.resolve(`node-libs-browser/mock/${module}`);
|
23
|
+
} else if(type === "empty") {
|
24
|
+
return require.resolve("node-libs-browser/mock/empty");
|
25
|
+
} else return module;
|
26
|
+
}
|
35
27
|
|
36
|
-
|
37
|
-
|
28
|
+
function addExpression(parser, name, module, type, suffix) {
|
29
|
+
suffix = suffix || "";
|
30
|
+
parser.plugin(`expression ${name}`, function() {
|
31
|
+
if(this.state.module && this.state.module.resource === getPathToModule(module, type)) return;
|
32
|
+
const mockModule = ParserHelpers.requireFileAsExpression(this.state.module.context, getPathToModule(module, type));
|
33
|
+
return ParserHelpers.addParsedVariableToModule(this, name, mockModule + suffix);
|
34
|
+
});
|
35
|
+
}
|
38
36
|
|
39
|
-
|
40
|
-
|
37
|
+
compiler.plugin("compilation", function(compilation, params) {
|
38
|
+
params.normalModuleFactory.plugin("parser", function(parser, parserOptions) {
|
41
39
|
|
42
|
-
|
43
|
-
|
44
|
-
localOptions = Object.assign({}, localOptions, parserOptions.node);
|
40
|
+
if(parserOptions.node === false)
|
41
|
+
return;
|
45
42
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
43
|
+
let localOptions = options;
|
44
|
+
if(parserOptions.node)
|
45
|
+
localOptions = Object.assign({}, localOptions, parserOptions.node);
|
46
|
+
|
47
|
+
if(localOptions.global) {
|
48
|
+
parser.plugin("expression global", function() {
|
49
|
+
const retrieveGlobalModule = ParserHelpers.requireFileAsExpression(this.state.module.context, require.resolve("../../buildin/global.js"));
|
50
|
+
return ParserHelpers.addParsedVariableToModule(this, "global", retrieveGlobalModule);
|
51
|
+
});
|
52
|
+
}
|
53
|
+
if(localOptions.process) {
|
54
|
+
const processType = localOptions.process;
|
55
|
+
addExpression(parser, "process", "process", processType);
|
56
|
+
}
|
57
|
+
if(localOptions.console) {
|
58
|
+
const consoleType = localOptions.console;
|
59
|
+
addExpression(parser, "console", "console", consoleType);
|
60
|
+
}
|
61
|
+
const bufferType = localOptions.Buffer;
|
62
|
+
if(bufferType) {
|
63
|
+
addExpression(parser, "Buffer", "buffer", bufferType, ".Buffer");
|
64
|
+
}
|
65
|
+
if(localOptions.setImmediate) {
|
66
|
+
const setImmediateType = localOptions.setImmediate;
|
67
|
+
addExpression(parser, "setImmediate", "timers", setImmediateType, ".setImmediate");
|
68
|
+
addExpression(parser, "clearImmediate", "timers", setImmediateType, ".clearImmediate");
|
69
|
+
}
|
70
|
+
});
|
69
71
|
});
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
}
|
72
|
+
compiler.plugin("after-resolvers", (compiler) => {
|
73
|
+
Object.keys(nodeLibsBrowser).forEach((lib) => {
|
74
|
+
if(options[lib] !== false) {
|
75
|
+
compiler.resolvers.normal.apply(
|
76
|
+
new AliasPlugin("described-resolve", {
|
77
|
+
name: lib,
|
78
|
+
onlyModule: true,
|
79
|
+
alias: getPathToModule(lib, options[lib])
|
80
|
+
}, "resolve")
|
81
|
+
);
|
82
|
+
}
|
83
|
+
});
|
82
84
|
});
|
83
|
-
}
|
85
|
+
}
|
84
86
|
};
|
@@ -29,22 +29,26 @@ class WebWorkerMainTemplatePlugin {
|
|
29
29
|
mainTemplate.plugin("require-ensure", function(_, chunk, hash) {
|
30
30
|
const chunkFilename = this.outputOptions.chunkFilename;
|
31
31
|
return this.asString([
|
32
|
-
"
|
33
|
-
"if(!installedChunks[chunkId]) {",
|
32
|
+
"return new Promise(function(resolve) {",
|
34
33
|
this.indent([
|
35
|
-
"
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
34
|
+
"// \"1\" is the signal for \"already loaded\"",
|
35
|
+
"if(!installedChunks[chunkId]) {",
|
36
|
+
this.indent([
|
37
|
+
"importScripts(" +
|
38
|
+
this.applyPluginsWaterfall("asset-path", JSON.stringify(chunkFilename), {
|
39
|
+
hash: "\" + " + this.renderCurrentHashCode(hash) + " + \"",
|
40
|
+
hashWithLength: function(length) {
|
41
|
+
return "\" + " + this.renderCurrentHashCode(hash, length) + " + \"";
|
42
|
+
}.bind(this),
|
43
|
+
chunk: {
|
44
|
+
id: "\" + chunkId + \""
|
45
|
+
}
|
46
|
+
}) + ");"
|
47
|
+
]),
|
48
|
+
"}",
|
49
|
+
"resolve();"
|
45
50
|
]),
|
46
|
-
"}"
|
47
|
-
"return Promise.resolve();"
|
51
|
+
"});"
|
48
52
|
]);
|
49
53
|
});
|
50
54
|
mainTemplate.plugin("bootstrap", function(source, chunk, hash) {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "webpack",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.7.0",
|
4
4
|
"author": "Tobias Koppers @sokra",
|
5
5
|
"description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
|
6
6
|
"dependencies": {
|
@@ -9,7 +9,7 @@
|
|
9
9
|
"ajv": "^4.7.0",
|
10
10
|
"ajv-keywords": "^1.1.1",
|
11
11
|
"async": "^2.1.2",
|
12
|
-
"enhanced-resolve": "^3.
|
12
|
+
"enhanced-resolve": "^3.3.0",
|
13
13
|
"interpret": "^1.0.0",
|
14
14
|
"json-loader": "^0.5.4",
|
15
15
|
"json5": "^0.5.1",
|
@@ -21,9 +21,9 @@
|
|
21
21
|
"source-map": "^0.5.3",
|
22
22
|
"supports-color": "^3.1.0",
|
23
23
|
"tapable": "~0.2.5",
|
24
|
-
"uglify-js": "^2.8.
|
24
|
+
"uglify-js": "^2.8.27",
|
25
25
|
"watchpack": "^1.3.1",
|
26
|
-
"webpack-sources": "^0.
|
26
|
+
"webpack-sources": "^1.0.1",
|
27
27
|
"yargs": "^6.0.0"
|
28
28
|
},
|
29
29
|
"license": "MIT",
|
@@ -88,13 +88,13 @@
|
|
88
88
|
"schemas/"
|
89
89
|
],
|
90
90
|
"scripts": {
|
91
|
-
"test": "mocha test/*.test.js --harmony --check-leaks",
|
91
|
+
"test": "mocha test/*.test.js --max_old_space_size=4096 --harmony --check-leaks",
|
92
92
|
"travis:test": "npm run cover:min",
|
93
93
|
"travis:lint": "npm run lint-files && npm run nsp",
|
94
94
|
"travis:benchmark": "npm run benchmark",
|
95
|
-
"appveyor:test": "node
|
95
|
+
"appveyor:test": "node node_modules\\mocha\\bin\\mocha --max_old_space_size=4096 --harmony test/*.test.js",
|
96
96
|
"appveyor:benchmark": "npm run benchmark",
|
97
|
-
"circleci:test": "node
|
97
|
+
"circleci:test": "node node_modules/mocha/bin/mocha --max_old_space_size=4096 --harmony test/*.test.js",
|
98
98
|
"circleci:lint": "npm run lint-files && npm run nsp",
|
99
99
|
"build:examples": "cd examples && node buildAll.js",
|
100
100
|
"pretest": "npm run lint-files",
|
@@ -102,9 +102,9 @@
|
|
102
102
|
"lint": "eslint lib bin hot buildin \"test/**/webpack.config.js\" \"test/binCases/**/test.js\" \"examples/**/webpack.config.js\"",
|
103
103
|
"beautify-lint": "beautify-lint \"lib/**/*.js\" \"hot/**/*.js\" \"bin/**/*.js\" \"benchmark/*.js\" \"test/*.js\"",
|
104
104
|
"nsp": "nsp check --output summary",
|
105
|
-
"benchmark": "mocha test/*.benchmark.js
|
106
|
-
"cover": "node --harmony ./node_modules/istanbul/lib/cli.js cover -x '**/*.runtime.js' node_modules/mocha/bin/_mocha -- test/*.test.js",
|
107
|
-
"cover:min": "node --harmony ./node_modules/.bin/istanbul cover -x '**/*.runtime.js' --report lcovonly node_modules/mocha/bin/_mocha -- test/*.test.js",
|
105
|
+
"benchmark": "mocha --max_old_space_size=4096 --harmony test/*.benchmark.js -R spec",
|
106
|
+
"cover": "node --max_old_space_size=4096 --harmony ./node_modules/istanbul/lib/cli.js cover -x '**/*.runtime.js' node_modules/mocha/bin/_mocha -- test/*.test.js",
|
107
|
+
"cover:min": "node --max_old_space_size=4096 --harmony ./node_modules/.bin/istanbul cover -x '**/*.runtime.js' --report lcovonly node_modules/mocha/bin/_mocha -- test/*.test.js",
|
108
108
|
"publish-patch": "npm run lint && npm run beautify-lint && mocha && npm version patch && git push && git push --tags && npm publish"
|
109
109
|
}
|
110
110
|
}
|
@@ -270,6 +270,10 @@
|
|
270
270
|
"use-credentials"
|
271
271
|
]
|
272
272
|
},
|
273
|
+
"chunkLoadTimeout": {
|
274
|
+
"description": "Number of milliseconds before chunk request expires",
|
275
|
+
"type": "number"
|
276
|
+
},
|
273
277
|
"devtoolFallbackModuleFilenameTemplate": {
|
274
278
|
"description": "Similar to `output.devtoolModuleFilenameTemplate`, but used in the case of duplicate module identifiers.",
|
275
279
|
"anyOf": [
|
@@ -455,6 +459,9 @@
|
|
455
459
|
"cachePredicate": {
|
456
460
|
"instanceof": "Function"
|
457
461
|
},
|
462
|
+
"cacheWithContext": {
|
463
|
+
"type": "boolean"
|
464
|
+
},
|
458
465
|
"descriptionFiles": {
|
459
466
|
"$ref": "#/definitions/common.arrayOfStringValues"
|
460
467
|
},
|