Merge pull request #10069 from smelukov/optimize-webpack-runtime-size

optimize webpack runtime size
This commit is contained in:
Tobias Koppers 2019-12-03 16:57:56 +01:00 committed by GitHub
commit 157c457241
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 470 additions and 382 deletions

View File

@ -545,7 +545,7 @@ function webpackContext(req) {
${returnModuleObject}
}
function webpackContextResolve(req) {
if(!Object.prototype.hasOwnProperty.call(map, req)) {
if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {
var e = new Error("Cannot find module '" + req + "'");
e.code = 'MODULE_NOT_FOUND';
throw e;
@ -584,7 +584,7 @@ function webpackContext(req) {
${returnModuleObject}
}
function webpackContextResolve(req) {
if(!Object.prototype.hasOwnProperty.call(map, req)) {
if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {
var e = new Error("Cannot find module '" + req + "'");
e.code = 'MODULE_NOT_FOUND';
throw e;
@ -632,7 +632,7 @@ function webpackAsyncContextResolve(req) {
// Here Promise.resolve().then() is used instead of new Promise() to prevent
// uncaught exception popping up in devtools
return Promise.resolve().then(${arrow ? "() =>" : "function()"} {
if(!Object.prototype.hasOwnProperty.call(map, req)) {
if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {
var e = new Error("Cannot find module '" + req + "'");
e.code = 'MODULE_NOT_FOUND';
throw e;
@ -640,9 +640,9 @@ function webpackAsyncContextResolve(req) {
return map[req];
});
}
webpackAsyncContext.keys = function webpackAsyncContextKeys() {
return Object.keys(map);
};
webpackAsyncContext.keys = ${runtimeTemplate.returningFunction(
"Object.keys(map)"
)};
webpackAsyncContext.resolve = webpackAsyncContextResolve;
webpackAsyncContext.id = ${JSON.stringify(id)};
module.exports = webpackAsyncContext;`;
@ -676,7 +676,7 @@ function webpackAsyncContextResolve(req) {
// Here Promise.resolve().then() is used instead of new Promise() to prevent
// uncaught exception popping up in devtools
return Promise.resolve().then(${arrow ? "() =>" : "function()"} {
if(!Object.prototype.hasOwnProperty.call(map, req)) {
if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {
var e = new Error("Cannot find module '" + req + "'");
e.code = 'MODULE_NOT_FOUND';
throw e;
@ -684,9 +684,9 @@ function webpackAsyncContextResolve(req) {
return map[req];
});
}
webpackAsyncContext.keys = function webpackAsyncContextKeys() {
return Object.keys(map);
};
webpackAsyncContext.keys = ${runtimeTemplate.returningFunction(
"Object.keys(map)"
)};
webpackAsyncContext.resolve = webpackAsyncContextResolve;
webpackAsyncContext.id = ${JSON.stringify(id)};
module.exports = webpackAsyncContext;`;
@ -726,7 +726,7 @@ function webpackAsyncContext(req) {
}
function webpackAsyncContextResolve(req) {
return ${promise}.then(${arrow ? "() =>" : "function()"} {
if(!Object.prototype.hasOwnProperty.call(map, req)) {
if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {
var e = new Error("Cannot find module '" + req + "'");
e.code = 'MODULE_NOT_FOUND';
throw e;
@ -734,9 +734,9 @@ function webpackAsyncContextResolve(req) {
return map[req];
});
}
webpackAsyncContext.keys = function webpackAsyncContextKeys() {
return Object.keys(map);
};
webpackAsyncContext.keys = ${runtimeTemplate.returningFunction(
"Object.keys(map)"
)};
webpackAsyncContext.resolve = webpackAsyncContextResolve;
webpackAsyncContext.id = ${JSON.stringify(id)};
module.exports = webpackAsyncContext;`;
@ -821,7 +821,7 @@ module.exports = webpackAsyncContext;`;
? `${shortMode ? "" : ""}
function webpackAsyncContext(req) {
return Promise.resolve().then(${arrow ? "() =>" : "function()"} {
if(!Object.prototype.hasOwnProperty.call(map, req)) {
if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {
var e = new Error("Cannot find module '" + req + "'");
e.code = 'MODULE_NOT_FOUND';
throw e;
@ -832,7 +832,7 @@ function webpackAsyncContext(req) {
});
}`
: `function webpackAsyncContext(req) {
if(!Object.prototype.hasOwnProperty.call(map, req)) {
if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {
return Promise.resolve().then(${arrow ? "() =>" : "function()"} {
var e = new Error("Cannot find module '" + req + "'");
e.code = 'MODULE_NOT_FOUND';
@ -848,9 +848,9 @@ function webpackAsyncContext(req) {
return `var map = ${JSON.stringify(map, null, "\t")};
${webpackAsyncContext}
webpackAsyncContext.keys = function webpackAsyncContextKeys() {
return Object.keys(map);
};
webpackAsyncContext.keys = ${runtimeTemplate.returningFunction(
"Object.keys(map)"
)};
webpackAsyncContext.id = ${JSON.stringify(id)};
module.exports = webpackAsyncContext;`;
}
@ -962,6 +962,7 @@ module.exports = webpackEmptyAsyncContext;`;
this.blocks.map(b => b.dependencies[0])
));
set.push(RuntimeGlobals.module);
set.push(RuntimeGlobals.hasOwnProperty);
if (allDeps.length > 0) {
const asyncMode = this.options.mode;
set.push(RuntimeGlobals.require);

View File

@ -199,3 +199,9 @@ exports.amdOptions = "__webpack_require__.amdO";
* the System polyfill object
*/
exports.system = "__webpack_require__.System";
/**
* the shorthand for Object.prototype.hasOwnProperty
* using of ot decreases the compiled bundle size
*/
exports.hasOwnProperty = "__webpack_require__.o";

View File

@ -16,6 +16,7 @@ const EnsureChunkRuntimeModule = require("./runtime/EnsureChunkRuntimeModule");
const GetChunkFilenameRuntimeModule = require("./runtime/GetChunkFilenameRuntimeModule");
const GetMainFilenameRuntimeModule = require("./runtime/GetMainFilenameRuntimeModule");
const GlobalRuntimeModule = require("./runtime/GlobalRuntimeModule");
const HasOwnPropertyRuntimeModule = require("./runtime/HasOwnPropertyRuntimeModule");
const MakeNamespaceObjectRuntimeModule = require("./runtime/MakeNamespaceObjectRuntimeModule");
const PublicPathRuntimeModule = require("./runtime/PublicPathRuntimeModule");
@ -45,6 +46,7 @@ const GLOBALS_ON_REQUIRE = [
];
const TREE_DEPENDENCIES = {
[RuntimeGlobals.definePropertyGetters]: [RuntimeGlobals.hasOwnProperty],
[RuntimeGlobals.compatGetDefaultExport]: [
RuntimeGlobals.definePropertyGetters
],
@ -113,6 +115,15 @@ class RuntimePlugin {
);
return true;
});
compilation.hooks.runtimeRequirementInTree
.for(RuntimeGlobals.hasOwnProperty)
.tap("RuntimePlugin", chunk => {
compilation.addRuntimeModule(
chunk,
new HasOwnPropertyRuntimeModule()
);
return true;
});
compilation.hooks.runtimeRequirementInTree
.for(RuntimeGlobals.compatGetDefaultExport)
.tap("RuntimePlugin", chunk => {

View File

@ -65,6 +65,10 @@ class RuntimeTemplate {
: `function(${args}) {\n${Template.indent(body)}\n}`;
}
iife(args, body) {
return `(${this.basicFunction(args, body)})()`;
}
forEach(variable, array, body) {
return this.supportsForOf()
? `for(const ${variable} of ${array}) {\n${Template.indent(body)}\n}`
@ -184,9 +188,12 @@ class RuntimeTemplate {
case "statements":
return errorStatements;
case "promise":
return `Promise.resolve().then(function() { ${errorStatements} })`;
return `Promise.resolve().then(${this.basicFunction(
"",
errorStatements
)})`;
case "expression":
return `(function() { ${errorStatements} }())`;
return this.iife("", errorStatements);
}
}
@ -430,7 +437,10 @@ class RuntimeTemplate {
weak,
runtimeRequirements
});
getModuleFunction = `function() { ${header}return ${rawModule}; }`;
getModuleFunction = this.basicFunction(
"",
`${header}return ${rawModule};`
);
} else {
runtimeRequirements.add(RuntimeGlobals.require);
getModuleFunction = `__webpack_require__.bind(null, ${comment}${idExpr})`;
@ -438,21 +448,30 @@ class RuntimeTemplate {
} else if (strict) {
runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
if (header) {
getModuleFunction = `function() { ${header}return ${RuntimeGlobals.createFakeNamespaceObject}(${moduleIdExpr}, 1); }`;
const returnExpression = `${RuntimeGlobals.createFakeNamespaceObject}(${moduleIdExpr}, 1)`;
getModuleFunction = header
? this.basicFunction("", `${header}return ${returnExpression};`)
: this.returningFunction(returnExpression);
} else {
getModuleFunction = `${RuntimeGlobals.createFakeNamespaceObject}.bind(__webpack_require__, ${comment}${idExpr}, 1)`;
}
} else if (exportsType === "default") {
runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
if (header) {
getModuleFunction = `function() { ${header}return ${RuntimeGlobals.createFakeNamespaceObject}(${moduleIdExpr}, 3); }`;
const returnExpression = `${RuntimeGlobals.createFakeNamespaceObject}(${moduleIdExpr}, 3)`;
getModuleFunction = header
? this.basicFunction("", `${header}return ${returnExpression};`)
: this.returningFunction(returnExpression);
} else {
getModuleFunction = `${RuntimeGlobals.createFakeNamespaceObject}.bind(__webpack_require__, ${comment}${idExpr}, 3)`;
}
} else {
runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
if (header) {
getModuleFunction = `function() { ${header}return ${RuntimeGlobals.createFakeNamespaceObject}(${moduleIdExpr}, 7); }`;
const returnExpression = `${RuntimeGlobals.createFakeNamespaceObject}(${moduleIdExpr}, 7)`;
getModuleFunction = header
? this.basicFunction("", `${header}return ${returnExpression};`)
: this.returningFunction(returnExpression);
} else {
getModuleFunction = `${RuntimeGlobals.createFakeNamespaceObject}.bind(__webpack_require__, ${comment}${idExpr}, 7)`;
}

View File

@ -892,8 +892,9 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
runtimeRequirements.add(RuntimeGlobals.exports);
runtimeRequirements.add(RuntimeGlobals.definePropertyGetters);
runtimeRequirements.add(RuntimeGlobals.hasOwnProperty);
return `if(Object.prototype.hasOwnProperty.call(${name}, ${JSON.stringify(
return `if(${RuntimeGlobals.hasOwnProperty}(${name}, ${JSON.stringify(
valueKey[0]
)})) ${
RuntimeGlobals.definePropertyGetters

View File

@ -496,7 +496,7 @@ class JavascriptModulesPlugin {
let source = new ConcatSource();
let prefix;
if (iife) {
if (runtimeTemplate.supportsConst()) {
if (runtimeTemplate.supportsArrowFunction()) {
source.add("/******/ (() => { // webpackBootstrap\n");
} else {
source.add("/******/ (function() { // webpackBootstrap\n");
@ -578,10 +578,17 @@ class JavascriptModulesPlugin {
const innerStrict = !allStrict && m.buildInfo.strict;
const iife = innerStrict || inlinedModules.size > 1 || chunkModules;
if (iife) {
source.add("!function() {\n");
if (innerStrict) source.add('"use strict";\n');
source.add(renderedModule);
source.add("\n}();\n");
if (runtimeTemplate.supportsArrowFunction()) {
source.add("(() => {\n");
if (innerStrict) source.add('"use strict";\n');
source.add(renderedModule);
source.add("\n})();\n\n");
} else {
source.add("!function() {\n");
if (innerStrict) source.add('"use strict";\n');
source.add(renderedModule);
source.add("\n}();\n");
}
} else {
source.add(renderedModule);
source.add("\n");

View File

@ -60,6 +60,7 @@ class NodeTemplatePlugin {
if (onceForChunkSet.has(chunk)) return;
onceForChunkSet.add(chunk);
set.add(RuntimeGlobals.moduleFactoriesAddOnly);
set.add(RuntimeGlobals.hasOwnProperty);
compilation.addRuntimeModule(chunk, new ChunkLoadingRuntimeModule(set));
};

View File

@ -77,7 +77,7 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
"var moreModules = chunk.modules, chunkIds = chunk.ids, runtime = chunk.runtime;",
"for(var moduleId in moreModules) {",
Template.indent([
"if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {",
`if(${RuntimeGlobals.hasOwnProperty}(moreModules, moduleId)) {`,
Template.indent([
`${RuntimeGlobals.moduleFactories}[moduleId] = moreModules[moduleId];`
]),
@ -148,7 +148,7 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
"var runtime = update.runtime;",
"for(var moduleId in updatedModules) {",
Template.indent([
"if(Object.prototype.hasOwnProperty.call(updatedModules, moduleId)) {",
`if(${RuntimeGlobals.hasOwnProperty}(updatedModules, moduleId)) {`,
Template.indent([
`currentUpdate[moduleId] = updatedModules[moduleId];`,
"if(updatedModulesList) updatedModulesList.push(moduleId);"

View File

@ -62,7 +62,7 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
"var moreModules = chunk.modules, chunkIds = chunk.ids, runtime = chunk.runtime;",
"for(var moduleId in moreModules) {",
Template.indent([
"if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {",
`if(${RuntimeGlobals.hasOwnProperty}(moreModules, moduleId)) {`,
Template.indent([
`${RuntimeGlobals.moduleFactories}[moduleId] = moreModules[moduleId];`
]),
@ -107,7 +107,7 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
"var runtime = update.runtime;",
"for(var moduleId in updatedModules) {",
Template.indent([
"if(Object.prototype.hasOwnProperty.call(updatedModules, moduleId)) {",
`if(${RuntimeGlobals.hasOwnProperty}(updatedModules, moduleId)) {`,
Template.indent([
`currentUpdate[moduleId] = updatedModules[moduleId];`,
"if(updatedModulesList) updatedModulesList.push(moduleId);"

View File

@ -21,11 +21,10 @@ class DefinePropertyGettersRuntimeModule extends HelperRuntimeModule {
const fn = RuntimeGlobals.definePropertyGetters;
return Template.asString([
"// define getter functions for harmony exports",
"var hasOwnProperty = Object.prototype.hasOwnProperty;",
`${fn} = ${runtimeTemplate.basicFunction("exports, definition", [
`for(var key in definition) {`,
Template.indent([
"if(hasOwnProperty.call(definition, key) && !hasOwnProperty.call(exports, key)) {",
`if(${RuntimeGlobals.hasOwnProperty}(definition, key) && !${RuntimeGlobals.hasOwnProperty}(exports, key)) {`,
Template.indent([
"Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });"
]),

View File

@ -0,0 +1,32 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Sergey Melyukov @smelukov
*/
"use strict";
const RuntimeGlobals = require("../RuntimeGlobals");
const RuntimeModule = require("../RuntimeModule");
const Template = require("../Template");
class HasOwnPropertyRuntimeModule extends RuntimeModule {
constructor() {
super("hasOwnProperty shorthand");
}
/**
* @returns {string} runtime code
*/
generate() {
const { runtimeTemplate } = this.compilation;
return Template.asString([
`${RuntimeGlobals.hasOwnProperty} = ${runtimeTemplate.returningFunction(
"Object.prototype.hasOwnProperty.call(obj, prop)",
"obj, prop"
)}`
]);
}
}
module.exports = HasOwnPropertyRuntimeModule;

View File

@ -112,7 +112,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
hasJsMatcher !== false
? Template.indent([
"// JSONP chunk loading for javascript",
`var installedChunkData = Object.prototype.hasOwnProperty.call(installedChunks, chunkId) ? installedChunks[chunkId] : undefined;`,
`var installedChunkData = ${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId) ? installedChunks[chunkId] : undefined;`,
'if(installedChunkData !== 0) { // 0 means "already installed".',
Template.indent([
"",
@ -141,7 +141,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
`var loadingEnded = ${runtimeTemplate.basicFunction(
"",
[
"if(Object.prototype.hasOwnProperty.call(installedChunks, chunkId)) {",
`if(${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId)) {`,
Template.indent([
"installedChunkData = installedChunks[chunkId];",
"if(installedChunkData !== 0) installedChunks[chunkId] = undefined;",
@ -173,7 +173,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
"chunkId",
"chunkPreloadData",
[
"if(!Object.prototype.hasOwnProperty.call(installedChunks, chunkId) || installedChunks[chunkId] === undefined) {",
`if(!${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId) || installedChunks[chunkId] === undefined) {`,
Template.indent([
"installedChunks[chunkId] = null;",
linkPreload.call("", chunk),
@ -202,7 +202,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
? Template.asString([
"function prefetchChunk(chunkId) {",
Template.indent([
"if(!Object.prototype.hasOwnProperty.call(installedChunks, chunkId) || installedChunks[chunkId] === undefined) {",
`if(!${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId) || installedChunks[chunkId] === undefined) {`,
Template.indent([
"installedChunks[chunkId] = null;",
linkPrefetch.call("", chunk),
@ -251,7 +251,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
[
"for(var moduleId in moreModules) {",
Template.indent([
"if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {",
`if(${RuntimeGlobals.hasOwnProperty}(moreModules, moduleId)) {`,
Template.indent([
"currentUpdate[moduleId] = moreModules[moduleId];",
"if(currentUpdatedModulesList) currentUpdatedModulesList.push(moduleId);"
@ -310,7 +310,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
"currentUpdateRuntime = [];",
"currentUpdatedModulesList = updatedModulesList;",
runtimeTemplate.forEach("chunkId", "chunkIds", [
"if(Object.prototype.hasOwnProperty.call(installedChunks, chunkId) && installedChunks[chunkId] !== undefined) {",
`if(${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId) && installedChunks[chunkId] !== undefined) {`,
Template.indent(["promises.push(loadUpdateChunk(chunkId));"]),
"}",
"currentUpdateChunks[chunkId] = true;"
@ -414,7 +414,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
"for(;i < chunkIds.length; i++) {",
Template.indent([
"chunkId = chunkIds[i];",
"if(Object.prototype.hasOwnProperty.call(installedChunks, chunkId) && installedChunks[chunkId]) {",
`if(${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId) && installedChunks[chunkId]) {`,
Template.indent("resolves.push(installedChunks[chunkId][0]);"),
"}",
"installedChunks[chunkId] = 0;"
@ -422,7 +422,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
"}",
"for(moduleId in moreModules) {",
Template.indent([
"if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {",
`if(${RuntimeGlobals.hasOwnProperty}(moreModules, moduleId)) {`,
Template.indent(
`${RuntimeGlobals.moduleFactories}[moduleId] = moreModules[moduleId];`
),

View File

@ -145,6 +145,7 @@ class JsonpTemplatePlugin {
linkPreload,
linkPrefetch
} = JsonpTemplatePlugin.getCompilationHooks(compilation);
const { runtimeTemplate } = compilation;
jsonpScript.tap("JsonpTemplatePlugin", (_, chunk, hash) => {
const {
@ -178,31 +179,33 @@ class JsonpTemplatePlugin {
: "",
"// create error before stack unwound to get useful stacktrace later",
"var error = new Error();",
"onScriptComplete = function (event) {",
Template.indent([
"onScriptComplete = function() {};",
"// avoid mem leaks in IE.",
"script.onerror = script.onload = null;",
"clearTimeout(timeout);",
"var reportError = loadingEnded();",
"if(reportError) {",
Template.indent([
"var errorType = event && (event.type === 'load' ? 'missing' : event.type);",
"var realSrc = event && event.target && event.target.src;",
"error.message = 'Loading chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realSrc + ')';",
"error.name = 'ChunkLoadError';",
"error.type = errorType;",
"error.request = realSrc;",
"reportError(error);"
]),
"}"
]),
"};",
"var timeout = setTimeout(function(){",
Template.indent([
"onScriptComplete({ type: 'timeout', target: script });"
]),
`}, ${chunkLoadTimeout});`,
"onScriptComplete = " +
runtimeTemplate.basicFunction(
"event",
Template.asString([
`onScriptComplete = ${runtimeTemplate.basicFunction("", "")}`,
"// avoid mem leaks in IE.",
"script.onerror = script.onload = null;",
"clearTimeout(timeout);",
"var reportError = loadingEnded();",
"if(reportError) {",
Template.indent([
"var errorType = event && (event.type === 'load' ? 'missing' : event.type);",
"var realSrc = event && event.target && event.target.src;",
"error.message = 'Loading chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realSrc + ')';",
"error.name = 'ChunkLoadError';",
"error.type = errorType;",
"error.request = realSrc;",
"reportError(error);"
]),
"}"
])
),
";",
`var timeout = setTimeout(${runtimeTemplate.basicFunction(
"",
"onScriptComplete({ type: 'timeout', target: script })"
)}, ${chunkLoadTimeout});`,
"script.onerror = script.onload = onScriptComplete;"
]);
});
@ -261,6 +264,7 @@ class JsonpTemplatePlugin {
if (onceForChunkSet.has(chunk)) return;
onceForChunkSet.add(chunk);
set.add(RuntimeGlobals.moduleFactoriesAddOnly);
set.add(RuntimeGlobals.hasOwnProperty);
compilation.addRuntimeModule(
chunk,
new JsonpChunkLoadingRuntimeModule(

View File

@ -57,7 +57,7 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
Template.indent([
"for(var moduleId in moreModules) {",
Template.indent([
"if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {",
`if(${RuntimeGlobals.hasOwnProperty}(moreModules, moduleId)) {`,
Template.indent(
`${RuntimeGlobals.moduleFactories}[moduleId] = moreModules[moduleId];`
),
@ -95,7 +95,7 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
Template.indent([
"for(var moduleId in moreModules) {",
Template.indent([
"if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {",
`if(${RuntimeGlobals.hasOwnProperty}(moreModules, moduleId)) {`,
Template.indent([
"currentUpdate[moduleId] = moreModules[moduleId];",
"if(updatedModulesList) updatedModulesList.push(moduleId);"

View File

@ -82,6 +82,7 @@ class WebWorkerTemplatePlugin {
if (onceForChunkSet.has(chunk)) return;
onceForChunkSet.add(chunk);
set.add(RuntimeGlobals.moduleFactoriesAddOnly);
set.add(RuntimeGlobals.hasOwnProperty);
compilation.addRuntimeModule(
chunk,
new ImportScriptsChunkLoadingRuntimeModule(set)

View File

@ -217,10 +217,10 @@ describe("Stats", () => {
"comparedForEmit": false,
"emitted": true,
"info": Object {
"size": 2036,
"size": 1881,
},
"name": "entryB.js",
"size": 2036,
"size": 1881,
},
],
"assetsByChunkName": Object {

File diff suppressed because it is too large Load Diff

View File

@ -9,5 +9,5 @@ it("should watch for changes", function() {
expect(require("./foo/" + WATCH_STEP)).toBe('This should be working.' + WATCH_STEP);
}
expect(STATS_JSON.modules.length).toBe(6 + Number(WATCH_STEP));
expect(STATS_JSON.modules.length).toBe(7 + Number(WATCH_STEP));
});