webpack 3.8.0 → 3.10.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/README.md +3 -0
- package/bin/webpack.js +10 -7
- package/lib/Compilation.js +1 -1
- package/lib/Compiler.js +22 -26
- package/lib/DllModuleFactory.js +2 -2
- package/lib/DllReferencePlugin.js +1 -1
- package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +1 -1
- package/lib/ExternalsPlugin.js +1 -1
- package/lib/FlagDependencyUsagePlugin.js +1 -1
- package/lib/HotModuleReplacementPlugin.js +5 -5
- package/lib/JsonpMainTemplatePlugin.js +2 -2
- package/lib/OptionsDefaulter.js +2 -2
- package/lib/SourceMapDevToolPlugin.js +3 -3
- package/lib/UmdMainTemplatePlugin.js +1 -1
- package/lib/WebpackOptionsValidationError.js +34 -11
- package/lib/dependencies/AMDDefineDependency.js +3 -3
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +18 -6
- package/lib/dependencies/AMDRequireDependency.js +4 -4
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +2 -2
- package/lib/dependencies/HarmonyImportDependency.js +1 -1
- package/lib/dependencies/LocalModulesHelpers.js +4 -4
- package/lib/dependencies/RequireIncludeDependency.js +8 -0
- package/lib/optimize/ConcatenatedModule.js +16 -6
- package/lib/webworker/WebWorkerMainTemplatePlugin.js +2 -2
- package/package.json +21 -10
- package/schemas/webpackOptionsSchema.json +370 -71
package/README.md
CHANGED
@@ -24,6 +24,9 @@
|
|
24
24
|
<a href="https://opencollective.com/webpack#sponsors">
|
25
25
|
<img src="https://opencollective.com/webpack/sponsors/badge.svg">
|
26
26
|
</a>
|
27
|
+
<a href="https://github.com/webpack/webpack/graphs/contributors">
|
28
|
+
<img src="https://img.shields.io/github/contributors/webpack/webpack.svg">
|
29
|
+
</a>
|
27
30
|
<a href="https://gitter.im/webpack/webpack">
|
28
31
|
<img src="https://badges.gitter.im/webpack/webpack.svg">
|
29
32
|
</a>
|
package/bin/webpack.js
CHANGED
@@ -333,16 +333,19 @@ yargs.parse(process.argv.slice(2), (err, argv, output) => {
|
|
333
333
|
var compiler;
|
334
334
|
try {
|
335
335
|
compiler = webpack(options);
|
336
|
-
} catch(
|
337
|
-
|
338
|
-
if(e instanceof WebpackOptionsValidationError) {
|
336
|
+
} catch(err) {
|
337
|
+
if(err.name === "WebpackOptionsValidationError") {
|
339
338
|
if(argv.color)
|
340
|
-
console.error(
|
339
|
+
console.error(
|
340
|
+
`\u001b[1m\u001b[31m${err.message}\u001b[39m\u001b[22m`
|
341
|
+
);
|
341
342
|
else
|
342
|
-
console.error(
|
343
|
-
|
343
|
+
console.error(err.message);
|
344
|
+
// eslint-disable-next-line no-process-exit
|
345
|
+
process.exit(1);
|
344
346
|
}
|
345
|
-
|
347
|
+
|
348
|
+
throw err;
|
346
349
|
}
|
347
350
|
|
348
351
|
if(argv.progress) {
|
package/lib/Compilation.js
CHANGED
@@ -1425,7 +1425,7 @@ class Compilation extends Tapable {
|
|
1425
1425
|
}
|
1426
1426
|
|
1427
1427
|
createChildCompiler(name, outputOptions, plugins) {
|
1428
|
-
|
1428
|
+
const idx = (this.childrenCounters[name] || 0);
|
1429
1429
|
this.childrenCounters[name] = idx + 1;
|
1430
1430
|
return this.compiler.createChildCompiler(this, name, idx, outputOptions, plugins);
|
1431
1431
|
}
|
package/lib/Compiler.js
CHANGED
@@ -6,6 +6,7 @@
|
|
6
6
|
|
7
7
|
const path = require("path");
|
8
8
|
const Tapable = require("tapable");
|
9
|
+
const util = require("util");
|
9
10
|
|
10
11
|
const Compilation = require("./Compilation");
|
11
12
|
const Stats = require("./Stats");
|
@@ -186,35 +187,30 @@ class Compiler extends Tapable {
|
|
186
187
|
loader: null,
|
187
188
|
context: null
|
188
189
|
};
|
189
|
-
let deprecationReported = false;
|
190
190
|
this.parser = {
|
191
|
-
plugin: (
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
}
|
198
|
-
this.plugin("compilation", (compilation, data) => {
|
199
|
-
data.normalModuleFactory.plugin("parser", parser => {
|
200
|
-
parser.plugin(hook, fn);
|
191
|
+
plugin: util.deprecate(
|
192
|
+
(hook, fn) => {
|
193
|
+
this.plugin("compilation", (compilation, data) => {
|
194
|
+
data.normalModuleFactory.plugin("parser", parser => {
|
195
|
+
parser.plugin(hook, fn);
|
196
|
+
});
|
201
197
|
});
|
202
|
-
}
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
data.normalModuleFactory.plugin("parser", parser => {
|
214
|
-
parser.apply.apply(parser, args);
|
198
|
+
},
|
199
|
+
"webpack: Using compiler.parser is deprecated.\n" +
|
200
|
+
"Use compiler.plugin(\"compilation\", function(compilation, data) {\n data.normalModuleFactory.plugin(\"parser\", function(parser, options) { parser.plugin(/* ... */); });\n}); instead. "
|
201
|
+
),
|
202
|
+
apply: util.deprecate(
|
203
|
+
() => {
|
204
|
+
const args = arguments;
|
205
|
+
this.plugin("compilation", (compilation, data) => {
|
206
|
+
data.normalModuleFactory.plugin("parser", parser => {
|
207
|
+
parser.apply.apply(parser, args);
|
208
|
+
});
|
215
209
|
});
|
216
|
-
}
|
217
|
-
|
210
|
+
},
|
211
|
+
"webpack: Using compiler.parser is deprecated.\n" +
|
212
|
+
"Use compiler.plugin(\"compilation\", function(compilation, data) {\n data.normalModuleFactory.plugin(\"parser\", function(parser, options) { parser.apply(/* ... */); });\n}); instead. "
|
213
|
+
)
|
218
214
|
};
|
219
215
|
|
220
216
|
this.options = {};
|
package/lib/DllModuleFactory.js
CHANGED
@@ -42,7 +42,7 @@ class DllReferencePlugin {
|
|
42
42
|
manifest = params["dll reference " + manifest];
|
43
43
|
}
|
44
44
|
const name = this.options.name || manifest.name;
|
45
|
-
const sourceType = this.options.sourceType || "var";
|
45
|
+
const sourceType = this.options.sourceType || (manifest && manifest.type) || "var";
|
46
46
|
const externals = {};
|
47
47
|
const source = "dll-reference " + name;
|
48
48
|
externals[source] = name;
|
@@ -55,7 +55,7 @@ class EvalSourceMapDevToolModuleTemplatePlugin {
|
|
55
55
|
sourceMap.sources = moduleFilenames;
|
56
56
|
if(sourceMap.sourcesContent) {
|
57
57
|
sourceMap.sourcesContent = sourceMap.sourcesContent.map(function(content, i) {
|
58
|
-
return `${content}\n\n\n${ModuleFilenameHelpers.createFooter(modules[i], this.requestShortener)}
|
58
|
+
return typeof content === "string" ? `${content}\n\n\n${ModuleFilenameHelpers.createFooter(modules[i], this.requestShortener)}` : null;
|
59
59
|
}, this);
|
60
60
|
}
|
61
61
|
sourceMap.sourceRoot = options.sourceRoot || "";
|
package/lib/ExternalsPlugin.js
CHANGED
@@ -30,7 +30,7 @@ class FlagDependencyUsagePlugin {
|
|
30
30
|
else if(usedExports === true)
|
31
31
|
module.usedExports = true;
|
32
32
|
else if(Array.isArray(usedExports)) {
|
33
|
-
|
33
|
+
const old = module.usedExports ? module.usedExports.length : -1;
|
34
34
|
module.usedExports = addToSet(module.usedExports || [], usedExports);
|
35
35
|
if(module.usedExports.length === old)
|
36
36
|
return;
|
@@ -25,6 +25,11 @@ module.exports = class HotModuleReplacementPlugin {
|
|
25
25
|
const requestTimeout = this.requestTimeout;
|
26
26
|
const hotUpdateChunkFilename = compiler.options.output.hotUpdateChunkFilename;
|
27
27
|
const hotUpdateMainFilename = compiler.options.output.hotUpdateMainFilename;
|
28
|
+
compiler.plugin("additional-pass", callback => {
|
29
|
+
if(multiStep)
|
30
|
+
return setTimeout(callback, fullBuildTimeout);
|
31
|
+
return callback();
|
32
|
+
});
|
28
33
|
compiler.plugin("compilation", (compilation, params) => {
|
29
34
|
const hotUpdateChunkTemplate = compilation.hotUpdateChunkTemplate;
|
30
35
|
if(!hotUpdateChunkTemplate) return;
|
@@ -88,11 +93,6 @@ module.exports = class HotModuleReplacementPlugin {
|
|
88
93
|
if(multiStep && !recompilation && !initialPass)
|
89
94
|
return true;
|
90
95
|
});
|
91
|
-
compiler.plugin("additional-pass", callback => {
|
92
|
-
if(multiStep)
|
93
|
-
return setTimeout(callback, fullBuildTimeout);
|
94
|
-
return callback();
|
95
|
-
});
|
96
96
|
compilation.plugin("additional-chunk-assets", function() {
|
97
97
|
const records = this.records;
|
98
98
|
if(records.hash === this.hash) return;
|
@@ -195,8 +195,8 @@ class JsonpMainTemplatePlugin {
|
|
195
195
|
function hotDisposeChunk(chunkId) {
|
196
196
|
delete installedChunks[chunkId];
|
197
197
|
}
|
198
|
-
var parentHotUpdateCallback =
|
199
|
-
|
198
|
+
var parentHotUpdateCallback = window[${JSON.stringify(hotUpdateFunction)}];
|
199
|
+
window[${JSON.stringify(hotUpdateFunction)}] = ${runtimeSource}`;
|
200
200
|
});
|
201
201
|
mainTemplate.plugin("hash", function(hash) {
|
202
202
|
hash.update("jsonp");
|
package/lib/OptionsDefaulter.js
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
function getProperty(obj, name) {
|
8
8
|
name = name.split(".");
|
9
|
-
for(
|
9
|
+
for(let i = 0; i < name.length - 1; i++) {
|
10
10
|
obj = obj[name[i]];
|
11
11
|
if(typeof obj !== "object" || !obj) return;
|
12
12
|
}
|
@@ -15,7 +15,7 @@ function getProperty(obj, name) {
|
|
15
15
|
|
16
16
|
function setProperty(obj, name, value) {
|
17
17
|
name = name.split(".");
|
18
|
-
for(
|
18
|
+
for(let i = 0; i < name.length - 1; i++) {
|
19
19
|
if(typeof obj[name[i]] !== "object" && typeof obj[name[i]] !== "undefined") return;
|
20
20
|
if(!obj[name[i]]) obj[name[i]] = {};
|
21
21
|
obj = obj[name[i]];
|
@@ -158,7 +158,7 @@ class SourceMapDevToolPlugin {
|
|
158
158
|
const moduleFilenames = modules.map(m => moduleToSourceNameMapping.get(m));
|
159
159
|
sourceMap.sources = moduleFilenames;
|
160
160
|
if(sourceMap.sourcesContent && !options.noSources) {
|
161
|
-
sourceMap.sourcesContent = sourceMap.sourcesContent.map((content, i) => `${content}\n\n\n${ModuleFilenameHelpers.createFooter(modules[i], requestShortener)}`);
|
161
|
+
sourceMap.sourcesContent = sourceMap.sourcesContent.map((content, i) => typeof content === "string" ? `${content}\n\n\n${ModuleFilenameHelpers.createFooter(modules[i], requestShortener)}` : null);
|
162
162
|
} else {
|
163
163
|
sourceMap.sourcesContent = undefined;
|
164
164
|
}
|
@@ -181,14 +181,14 @@ class SourceMapDevToolPlugin {
|
|
181
181
|
}
|
182
182
|
let sourceMapFile = compilation.getPath(sourceMapFilename, {
|
183
183
|
chunk,
|
184
|
-
filename,
|
184
|
+
filename: options.fileContext ? path.relative(options.fileContext, filename) : filename,
|
185
185
|
query,
|
186
186
|
basename: basename(filename)
|
187
187
|
});
|
188
188
|
if(sourceMapFile.indexOf("[contenthash]") !== -1) {
|
189
189
|
sourceMapFile = sourceMapFile.replace(/\[contenthash\]/g, crypto.createHash("md5").update(sourceMapString).digest("hex"));
|
190
190
|
}
|
191
|
-
const sourceMapUrl = path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/");
|
191
|
+
const sourceMapUrl = options.publicPath ? options.publicPath + sourceMapFile.replace(/\\/g, "/") : path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/");
|
192
192
|
if(currentSourceMappingURLComment !== false) {
|
193
193
|
asset.__SourceMapDevToolData[file] = compilation.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment.replace(/\[url\]/g, sourceMapUrl));
|
194
194
|
}
|
@@ -171,7 +171,7 @@ class UmdMainTemplatePlugin {
|
|
171
171
|
" for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n" +
|
172
172
|
" }\n"
|
173
173
|
) +
|
174
|
-
"})(this, function(" + externalsArguments(externals) + ") {\nreturn ", "webpack/universalModuleDefinition"), source, ";\n})");
|
174
|
+
"})(typeof self !== 'undefined' ? self : this, function(" + externalsArguments(externals) + ") {\nreturn ", "webpack/universalModuleDefinition"), source, ";\n})");
|
175
175
|
});
|
176
176
|
mainTemplate.plugin("global-hash-paths", (paths) => {
|
177
177
|
if(this.names.root) paths = paths.concat(this.names.root);
|
@@ -35,10 +35,21 @@ const getSchemaPartText = (schemaPart, additionalPath) => {
|
|
35
35
|
while(schemaPart.$ref) schemaPart = getSchemaPart(schemaPart.$ref);
|
36
36
|
let schemaText = WebpackOptionsValidationError.formatSchema(schemaPart);
|
37
37
|
if(schemaPart.description)
|
38
|
-
schemaText += `\n${schemaPart.description}`;
|
38
|
+
schemaText += `\n-> ${schemaPart.description}`;
|
39
39
|
return schemaText;
|
40
40
|
};
|
41
41
|
|
42
|
+
const getSchemaPartDescription = schemaPart => {
|
43
|
+
while(schemaPart.$ref) schemaPart = getSchemaPart(schemaPart.$ref);
|
44
|
+
if(schemaPart.description)
|
45
|
+
return `\n-> ${schemaPart.description}`;
|
46
|
+
return "";
|
47
|
+
};
|
48
|
+
|
49
|
+
const filterChildren = children => {
|
50
|
+
return children.filter(err => err.keyword !== "anyOf" && err.keyword !== "allOf" && err.keyword !== "oneOf");
|
51
|
+
};
|
52
|
+
|
42
53
|
const indent = (str, prefix, firstLine) => {
|
43
54
|
if(firstLine) {
|
44
55
|
return prefix + str.replace(/\n(?!$)/g, "\n" + prefix);
|
@@ -143,8 +154,16 @@ class WebpackOptionsValidationError extends WebpackError {
|
|
143
154
|
return baseMessage;
|
144
155
|
} else if(err.keyword === "oneOf" || err.keyword === "anyOf") {
|
145
156
|
if(err.children && err.children.length > 0) {
|
157
|
+
if(err.schema.length === 1) {
|
158
|
+
const lastChild = err.children[err.children.length - 1];
|
159
|
+
const remainingChildren = err.children.slice(0, err.children.length - 1);
|
160
|
+
return WebpackOptionsValidationError.formatValidationError(Object.assign({}, lastChild, {
|
161
|
+
children: remainingChildren,
|
162
|
+
parentSchema: Object.assign({}, err.parentSchema, lastChild.parentSchema)
|
163
|
+
}));
|
164
|
+
}
|
146
165
|
return `${dataPath} should be one of these:\n${getSchemaPartText(err.parentSchema)}\n` +
|
147
|
-
`Details:\n${err.children.map(err => " * " + indent(WebpackOptionsValidationError.formatValidationError(err), " ", false)).join("\n")}`;
|
166
|
+
`Details:\n${filterChildren(err.children).map(err => " * " + indent(WebpackOptionsValidationError.formatValidationError(err), " ", false)).join("\n")}`;
|
148
167
|
}
|
149
168
|
return `${dataPath} should be one of these:\n${getSchemaPartText(err.parentSchema)}`;
|
150
169
|
|
@@ -158,29 +177,33 @@ class WebpackOptionsValidationError extends WebpackError {
|
|
158
177
|
} else if(err.keyword === "type") {
|
159
178
|
switch(err.params.type) {
|
160
179
|
case "object":
|
161
|
-
return `${dataPath} should be an object
|
180
|
+
return `${dataPath} should be an object.${getSchemaPartDescription(err.parentSchema)}`;
|
162
181
|
case "string":
|
163
|
-
return `${dataPath} should be a string
|
182
|
+
return `${dataPath} should be a string.${getSchemaPartDescription(err.parentSchema)}`;
|
164
183
|
case "boolean":
|
165
|
-
return `${dataPath} should be a boolean
|
184
|
+
return `${dataPath} should be a boolean.${getSchemaPartDescription(err.parentSchema)}`;
|
166
185
|
case "number":
|
167
|
-
return `${dataPath} should be a number
|
186
|
+
return `${dataPath} should be a number.${getSchemaPartDescription(err.parentSchema)}`;
|
168
187
|
case "array":
|
169
188
|
return `${dataPath} should be an array:\n${getSchemaPartText(err.parentSchema)}`;
|
170
189
|
}
|
171
190
|
return `${dataPath} should be ${err.params.type}:\n${getSchemaPartText(err.parentSchema)}`;
|
172
191
|
} else if(err.keyword === "instanceof") {
|
173
|
-
return `${dataPath} should be an instance of ${getSchemaPartText(err.parentSchema)}
|
192
|
+
return `${dataPath} should be an instance of ${getSchemaPartText(err.parentSchema)}`;
|
174
193
|
} else if(err.keyword === "required") {
|
175
194
|
const missingProperty = err.params.missingProperty.replace(/^\./, "");
|
176
195
|
return `${dataPath} misses the property '${missingProperty}'.\n${getSchemaPartText(err.parentSchema, ["properties", missingProperty])}`;
|
177
|
-
} else if(err.keyword === "
|
196
|
+
} else if(err.keyword === "minimum") {
|
197
|
+
return `${dataPath} ${err.message}.${getSchemaPartDescription(err.parentSchema)}`;
|
198
|
+
} else if(err.keyword === "uniqueItems") {
|
199
|
+
return `${dataPath} should not contain the item '${err.data[err.params.i]}' twice.${getSchemaPartDescription(err.parentSchema)}`;
|
200
|
+
} else if(err.keyword === "minLength" || err.keyword === "minItems" || err.keyword === "minProperties") {
|
178
201
|
if(err.params.limit === 1)
|
179
|
-
return `${dataPath} should not be empty
|
202
|
+
return `${dataPath} should not be empty.${getSchemaPartDescription(err.parentSchema)}`;
|
180
203
|
else
|
181
|
-
return `${dataPath} ${err.message}`;
|
204
|
+
return `${dataPath} ${err.message}${getSchemaPartDescription(err.parentSchema)}`;
|
182
205
|
} else if(err.keyword === "absolutePath") {
|
183
|
-
const baseMessage = `${dataPath}: ${err.message}`;
|
206
|
+
const baseMessage = `${dataPath}: ${err.message}${getSchemaPartDescription(err.parentSchema)}`;
|
184
207
|
if(dataPath === "configuration.output.filename") {
|
185
208
|
return `${baseMessage}\n` +
|
186
209
|
"Please use output.path to specify absolute path and output.filename for the file name.";
|
@@ -25,7 +25,7 @@ AMDDefineDependency.Template = class AMDDefineDependencyTemplate {
|
|
25
25
|
return {
|
26
26
|
f: [
|
27
27
|
"var __WEBPACK_AMD_DEFINE_RESULT__;",
|
28
|
-
`!(__WEBPACK_AMD_DEFINE_RESULT__ =
|
28
|
+
`!(__WEBPACK_AMD_DEFINE_RESULT__ = (#).call(exports, __webpack_require__, exports, module),
|
29
29
|
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__))`
|
30
30
|
],
|
31
31
|
o: [
|
@@ -42,7 +42,7 @@ AMDDefineDependency.Template = class AMDDefineDependencyTemplate {
|
|
42
42
|
],
|
43
43
|
af: [
|
44
44
|
"var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;",
|
45
|
-
`!(__WEBPACK_AMD_DEFINE_ARRAY__ = #, __WEBPACK_AMD_DEFINE_RESULT__ =
|
45
|
+
`!(__WEBPACK_AMD_DEFINE_ARRAY__ = #, __WEBPACK_AMD_DEFINE_RESULT__ = (#).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
|
46
46
|
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__))`
|
47
47
|
],
|
48
48
|
ao: [
|
@@ -70,7 +70,7 @@ AMDDefineDependency.Template = class AMDDefineDependencyTemplate {
|
|
70
70
|
],
|
71
71
|
laf: [
|
72
72
|
"var __WEBPACK_AMD_DEFINE_ARRAY__, XXX;",
|
73
|
-
"!(__WEBPACK_AMD_DEFINE_ARRAY__ = #, XXX = (
|
73
|
+
"!(__WEBPACK_AMD_DEFINE_ARRAY__ = #, XXX = ((#).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)))"
|
74
74
|
],
|
75
75
|
lao: [
|
76
76
|
"var XXX;",
|
@@ -23,6 +23,18 @@ function isBoundFunctionExpression(expr) {
|
|
23
23
|
return true;
|
24
24
|
}
|
25
25
|
|
26
|
+
function isUnboundFunctionExpression(expr) {
|
27
|
+
if(expr.type === "FunctionExpression") return true;
|
28
|
+
if(expr.type === "ArrowFunctionExpression") return true;
|
29
|
+
return false;
|
30
|
+
}
|
31
|
+
|
32
|
+
function isCallable(expr) {
|
33
|
+
if(isUnboundFunctionExpression(expr)) return true;
|
34
|
+
if(isBoundFunctionExpression(expr)) return true;
|
35
|
+
return false;
|
36
|
+
}
|
37
|
+
|
26
38
|
class AMDDefineDependencyParserPlugin {
|
27
39
|
constructor(options) {
|
28
40
|
this.options = options;
|
@@ -38,7 +50,7 @@ class AMDDefineDependencyParserPlugin {
|
|
38
50
|
let array, fn, obj, namedModule;
|
39
51
|
switch(expr.arguments.length) {
|
40
52
|
case 1:
|
41
|
-
if(
|
53
|
+
if(isCallable(expr.arguments[0])) {
|
42
54
|
// define(f() {...})
|
43
55
|
fn = expr.arguments[0];
|
44
56
|
} else if(expr.arguments[0].type === "ObjectExpression") {
|
@@ -54,7 +66,7 @@ class AMDDefineDependencyParserPlugin {
|
|
54
66
|
if(expr.arguments[0].type === "Literal") {
|
55
67
|
namedModule = expr.arguments[0].value;
|
56
68
|
// define("...", ...)
|
57
|
-
if(
|
69
|
+
if(isCallable(expr.arguments[1])) {
|
58
70
|
// define("...", f() {...})
|
59
71
|
fn = expr.arguments[1];
|
60
72
|
} else if(expr.arguments[1].type === "ObjectExpression") {
|
@@ -67,7 +79,7 @@ class AMDDefineDependencyParserPlugin {
|
|
67
79
|
}
|
68
80
|
} else {
|
69
81
|
array = expr.arguments[0];
|
70
|
-
if(
|
82
|
+
if(isCallable(expr.arguments[1])) {
|
71
83
|
// define([...], f() {})
|
72
84
|
fn = expr.arguments[1];
|
73
85
|
} else if(expr.arguments[1].type === "ObjectExpression") {
|
@@ -84,7 +96,7 @@ class AMDDefineDependencyParserPlugin {
|
|
84
96
|
// define("...", [...], f() {...})
|
85
97
|
namedModule = expr.arguments[0].value;
|
86
98
|
array = expr.arguments[1];
|
87
|
-
if(
|
99
|
+
if(isCallable(expr.arguments[2])) {
|
88
100
|
// define("...", [...], f() {})
|
89
101
|
fn = expr.arguments[2];
|
90
102
|
} else if(expr.arguments[2].type === "ObjectExpression") {
|
@@ -102,7 +114,7 @@ class AMDDefineDependencyParserPlugin {
|
|
102
114
|
let fnParams = null;
|
103
115
|
let fnParamsOffset = 0;
|
104
116
|
if(fn) {
|
105
|
-
if(fn
|
117
|
+
if(isUnboundFunctionExpression(fn)) fnParams = fn.params;
|
106
118
|
else if(isBoundFunctionExpression(fn)) {
|
107
119
|
fnParams = fn.callee.object.params;
|
108
120
|
fnParamsOffset = fn.arguments.length - 1;
|
@@ -134,7 +146,7 @@ class AMDDefineDependencyParserPlugin {
|
|
134
146
|
});
|
135
147
|
}
|
136
148
|
let inTry;
|
137
|
-
if(fn && fn
|
149
|
+
if(fn && isUnboundFunctionExpression(fn)) {
|
138
150
|
inTry = parser.scope.inTry;
|
139
151
|
parser.inScope(fnParams, () => {
|
140
152
|
parser.scope.renames = fnRenames;
|
@@ -44,8 +44,8 @@ AMDRequireDependency.Template = class AMDRequireDependencyTemplate {
|
|
44
44
|
|
45
45
|
source.replace(depBlock.outerRange[0], depBlock.arrayRange[0] - 1, startBlock);
|
46
46
|
source.insert(depBlock.arrayRange[0] + 0.9, "var __WEBPACK_AMD_REQUIRE_ARRAY__ = ");
|
47
|
-
source.replace(depBlock.arrayRange[1], depBlock.functionRange[0] - 1, "; (");
|
48
|
-
source.insert(depBlock.functionRange[1], ".apply(null, __WEBPACK_AMD_REQUIRE_ARRAY__));");
|
47
|
+
source.replace(depBlock.arrayRange[1], depBlock.functionRange[0] - 1, "; ((");
|
48
|
+
source.insert(depBlock.functionRange[1], ").apply(null, __WEBPACK_AMD_REQUIRE_ARRAY__));");
|
49
49
|
source.replace(depBlock.functionRange[1], depBlock.errorCallbackRange[0] - 1, errorRangeBlock);
|
50
50
|
source.replace(depBlock.errorCallbackRange[1], depBlock.outerRange[1] - 1, endBlock);
|
51
51
|
return;
|
@@ -57,8 +57,8 @@ AMDRequireDependency.Template = class AMDRequireDependencyTemplate {
|
|
57
57
|
const endBlock = `}${depBlock.functionBindThis ? ".bind(this)" : ""}${wrapper[1]}__webpack_require__.oe${wrapper[2]}`;
|
58
58
|
source.replace(depBlock.outerRange[0], depBlock.arrayRange[0] - 1, startBlock);
|
59
59
|
source.insert(depBlock.arrayRange[0] + 0.9, "var __WEBPACK_AMD_REQUIRE_ARRAY__ = ");
|
60
|
-
source.replace(depBlock.arrayRange[1], depBlock.functionRange[0] - 1, "; (");
|
61
|
-
source.insert(depBlock.functionRange[1], ".apply(null, __WEBPACK_AMD_REQUIRE_ARRAY__));");
|
60
|
+
source.replace(depBlock.arrayRange[1], depBlock.functionRange[0] - 1, "; ((");
|
61
|
+
source.insert(depBlock.functionRange[1], ").apply(null, __WEBPACK_AMD_REQUIRE_ARRAY__));");
|
62
62
|
source.replace(depBlock.functionRange[1], depBlock.outerRange[1] - 1, endBlock);
|
63
63
|
}
|
64
64
|
}
|
@@ -9,7 +9,7 @@ const HarmonyCompatibilityDependency = require("./HarmonyCompatibilityDependency
|
|
9
9
|
module.exports = class HarmonyDetectionParserPlugin {
|
10
10
|
apply(parser) {
|
11
11
|
parser.plugin("program", (ast) => {
|
12
|
-
|
12
|
+
const isHarmony = ast.body.some(statement => {
|
13
13
|
return /^(Import|Export).*Declaration$/.test(statement.type);
|
14
14
|
});
|
15
15
|
if(isHarmony) {
|
@@ -32,7 +32,7 @@ module.exports = class HarmonyDetectionParserPlugin {
|
|
32
32
|
module.exportsArgument = "__webpack_exports__";
|
33
33
|
}
|
34
34
|
});
|
35
|
-
|
35
|
+
const nonHarmonyIdentifiers = ["define", "exports"];
|
36
36
|
nonHarmonyIdentifiers.forEach(identifer => {
|
37
37
|
parser.plugin(`evaluate typeof ${identifer}`, nullInHarmony);
|
38
38
|
parser.plugin(`typeof ${identifer}`, skipInHarmony);
|
@@ -3,7 +3,7 @@
|
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
5
|
"use strict";
|
6
|
-
|
6
|
+
const ModuleDependency = require("./ModuleDependency");
|
7
7
|
|
8
8
|
class HarmonyImportDependency extends ModuleDependency {
|
9
9
|
constructor(request, importedVar, range) {
|
@@ -14,8 +14,8 @@ const lookup = (parent, mod) => {
|
|
14
14
|
segs = mod.split("/");
|
15
15
|
path.pop();
|
16
16
|
|
17
|
-
for(
|
18
|
-
|
17
|
+
for(let i = 0; i < segs.length; i++) {
|
18
|
+
const seg = segs[i];
|
19
19
|
if(seg === "..") path.pop();
|
20
20
|
else if(seg !== ".") path.push(seg);
|
21
21
|
}
|
@@ -25,7 +25,7 @@ const lookup = (parent, mod) => {
|
|
25
25
|
|
26
26
|
LocalModulesHelpers.addLocalModule = (state, name) => {
|
27
27
|
if(!state.localModules) state.localModules = [];
|
28
|
-
|
28
|
+
const m = new LocalModule(state.module, name, state.localModules.length);
|
29
29
|
state.localModules.push(m);
|
30
30
|
return m;
|
31
31
|
};
|
@@ -36,7 +36,7 @@ LocalModulesHelpers.getLocalModule = (state, name, namedModule) => {
|
|
36
36
|
// resolve dependency name relative to the defining named module
|
37
37
|
name = lookup(namedModule, name);
|
38
38
|
}
|
39
|
-
for(
|
39
|
+
for(let i = 0; i < state.localModules.length; i++) {
|
40
40
|
if(state.localModules[i].name === name)
|
41
41
|
return state.localModules[i];
|
42
42
|
}
|
@@ -11,6 +11,14 @@ class RequireIncludeDependency extends ModuleDependency {
|
|
11
11
|
this.range = range;
|
12
12
|
}
|
13
13
|
|
14
|
+
getReference() {
|
15
|
+
if(!this.module) return null;
|
16
|
+
return {
|
17
|
+
module: this.module,
|
18
|
+
importedNames: [] // This doesn't use any export
|
19
|
+
};
|
20
|
+
}
|
21
|
+
|
14
22
|
get type() {
|
15
23
|
return "require.include";
|
16
24
|
}
|
@@ -7,6 +7,7 @@
|
|
7
7
|
const Module = require("../Module");
|
8
8
|
const Template = require("../Template");
|
9
9
|
const Parser = require("../Parser");
|
10
|
+
const crypto = require("crypto");
|
10
11
|
const acorn = require("acorn");
|
11
12
|
const escope = require("escope");
|
12
13
|
const ReplaceSource = require("webpack-sources/lib/ReplaceSource");
|
@@ -210,6 +211,7 @@ class ConcatenatedModule extends Module {
|
|
210
211
|
Object.assign(this.assets, m.assets);
|
211
212
|
}
|
212
213
|
}
|
214
|
+
this._identifier = this._createIdentifier();
|
213
215
|
}
|
214
216
|
|
215
217
|
get modules() {
|
@@ -219,12 +221,7 @@ class ConcatenatedModule extends Module {
|
|
219
221
|
}
|
220
222
|
|
221
223
|
identifier() {
|
222
|
-
return this.
|
223
|
-
switch(info.type) {
|
224
|
-
case "concatenated":
|
225
|
-
return info.module.identifier();
|
226
|
-
}
|
227
|
-
}).filter(Boolean).join(" ");
|
224
|
+
return this._identifier;
|
228
225
|
}
|
229
226
|
|
230
227
|
readableIdentifier(requestShortener) {
|
@@ -297,6 +294,19 @@ class ConcatenatedModule extends Module {
|
|
297
294
|
return list;
|
298
295
|
}
|
299
296
|
|
297
|
+
_createIdentifier() {
|
298
|
+
let orderedConcatenationListIdentifiers = "";
|
299
|
+
for(let i = 0; i < this._orderedConcatenationList.length; i++) {
|
300
|
+
if(this._orderedConcatenationList[i].type === "concatenated") {
|
301
|
+
orderedConcatenationListIdentifiers += this._orderedConcatenationList[i].module.identifier();
|
302
|
+
orderedConcatenationListIdentifiers += " ";
|
303
|
+
}
|
304
|
+
}
|
305
|
+
const hash = crypto.createHash("md5");
|
306
|
+
hash.update(orderedConcatenationListIdentifiers);
|
307
|
+
return this.rootModule.identifier() + " " + hash.digest("hex");
|
308
|
+
}
|
309
|
+
|
300
310
|
source(dependencyTemplates, outputOptions, requestShortener) {
|
301
311
|
// Metainfo for each module
|
302
312
|
const modulesWithInfo = this._orderedConcatenationList.map((info, idx) => {
|
@@ -82,8 +82,8 @@ class WebWorkerMainTemplatePlugin {
|
|
82
82
|
});
|
83
83
|
|
84
84
|
return source + "\n" +
|
85
|
-
`var parentHotUpdateCallback =
|
86
|
-
`
|
85
|
+
`var parentHotUpdateCallback = self[${JSON.stringify(hotUpdateFunction)}];\n` +
|
86
|
+
`self[${JSON.stringify(hotUpdateFunction)}] = ` +
|
87
87
|
Template.getFunctionContent(require("./WebWorkerMainTemplate.runtime.js"))
|
88
88
|
.replace(/\/\/\$semicolon/g, ";")
|
89
89
|
.replace(/\$require\$/g, this.requireFn)
|