chunkTemplate.plugin("render", function(modules, chunk) { var source = new ConcatSource(); source.add("exports.ids = " + JSON.stringify(chunk.ids) + ";\nexports.modules = "); source.add(modules); source.add(";"); return source; });
moduleTemplate.plugin("render", function(moduleSource, module) { var source = new ConcatSource(); source.add("/***/ function(" + ["module", "exports", "__webpack_require__"].concat(module.arguments || []).join(", ") + ") {\n\n"); source.add(new PrefixSource(this.outputOptions.sourcePrefix, moduleSource)); source.add("\n\n/***/ }"); return source; });
chunkTemplate.plugin("render", function(modules, chunk) { var jsonpFunction = this.outputOptions.jsonpFunction || Template.toIdentifier("webpackJsonp" + (this.outputOptions.library || "")); var source = new ConcatSource(); source.add(jsonpFunction + "(" + JSON.stringify(chunk.ids) + ","); source.add(modules); source.add(");"); return source; });
HotUpdateChunkTemplate.prototype.render = function(id, modules, hash, moduleTemplate, dependencyTemplates) { var source = new ConcatSource(); source.add(this.asString(this.renderHeader(id, modules, hash))); source.add(this.renderChunkModules({ id: id, modules: modules }, moduleTemplate, dependencyTemplates)); source.add(this.asString(this.renderFooter(id, modules, hash))); return source; };
moduleTemplate.plugin("render", function(moduleSource, module) { var source = new ConcatSource(); var defaultArguments = ["module", "exports"]; if((module.arguments && module.arguments.length !== 0) || module.hasDependencies()) { defaultArguments.push("__webpack_require__"); } source.add("/***/ (function(" + defaultArguments.concat(module.arguments || []).join(", ") + ") {\n\n"); source.add(new PrefixSource(this.outputOptions.sourcePrefix, moduleSource)); source.add("\n\n/***/ })"); return source; });
moduleTemplate.plugin("package", function(moduleSource, module) { if(this.outputOptions.pathinfo) { var source = new ConcatSource(); var req = module.readableIdentifier(this.requestShortener); source.add("/*!****" + req.replace(/./g, "*") + "****!*\\\n"); source.add(" !*** " + req.replace(/\*\//g, "*_/") + " ***!\n"); source.add(" \\****" + req.replace(/./g, "*") + "****/\n"); source.add(moduleSource); return source; } return moduleSource; });
MainTemplate.prototype.renderModules = function renderModules(hash, chunk, moduleTemplate, dependencyTemplates) { var source = new ConcatSource(); source.add("{\n"); source.add(this.asString(this.renderInitModules(hash, chunk, moduleTemplate, dependencyTemplates))); source.add("\n"); chunk.modules.forEach(function(module, idx) { if(idx != 0) source.add(",\n"); source.add("\n/***/ " + module.id + ":\n"); source.add(moduleTemplate.render(module, dependencyTemplates, chunk)); }); source.add("\n/******/ }"); return source; };
compilation.mainTemplate.plugin("modules", function(orginalSource, chunk) { if(!chunk.__DedupePluginHasDeduplicatedModules) { return orginalSource; } var source = new ConcatSource(); source.add("(function(modules) {\n"); source.add(this.indent([ "// Check all modules for deduplicated modules", "for(var i in modules) {", this.indent([ "if(Object.prototype.hasOwnProperty.call(modules, i)) {", this.indent([ "switch(typeof modules[i]) {", "case \"number\":", this.indent([ "// Module is a copy of another module", "modules[i] = modules[modules[i]];", "break;" ]), "case \"object\":", this.indent([ "// Module can be created from a template", "modules[i] = (function(_m) {", this.indent([ "var args = _m.slice(1), fn = modules[_m[0]];", "return function (a,b,c) {", this.indent([ "fn.apply(null, [a,b,c].concat(args));" ]), "};" ]), "}(modules[i]));" ]), "}" ]), "}" ]), "}", "return modules;" ])); source.add("\n}("); source.add(orginalSource); source.add("))"); return source; });
MainTemplate.prototype.render = function(hash, chunk, moduleTemplate, dependencyTemplates) { var buf = []; buf.push(this.asString(this.renderAdditions(hash, chunk, moduleTemplate, dependencyTemplates))); buf.push(this.asString(this.renderLocalVars(hash, chunk))); buf.push(""); buf.push("// The require function"); buf.push("function " + this.requireFn + "(moduleId) {"); buf.push(this.indent(this.renderRequireContent(hash, chunk))); buf.push("}"); buf.push(""); buf.push(this.asString(this.renderRequireExtensions(hash, chunk))); buf.push(this.asString(this.renderInit(hash, chunk))); if(chunk.modules.some(function(m) { return m.id === 0; })) { buf.push(""); buf.push("// Load entry module and return exports"); buf.push("return " + this.renderRequireFunctionForModule(hash, chunk, "0") + "(0);"); } var source = new ConcatSource(); source.add("/******/ (function(modules) { // webpackBootstrap\n"); source.add(new PrefixSource("/******/ \t", new OriginalSource(this.asString(buf), "webpack/bootstrap " + hash))); source.add("\n/******/ })\n"); source.add("/************************************************************************/\n"); source.add("/******/ ("); source.add(this.renderModules(hash, chunk, moduleTemplate, dependencyTemplates)); source.add(")"); chunk.rendered = true; return source; };
this.plugin("render", function(bootstrapSource, chunk, hash, moduleTemplate, dependencyTemplates) { var source = new ConcatSource(); source.add("/******/ (function(modules) { // webpackBootstrap\n"); source.add(new PrefixSource("/******/", bootstrapSource)); source.add("\n/******/ })\n"); source.add("/************************************************************************/\n"); source.add("/******/ ("); var modules = this.renderChunkModules(chunk, moduleTemplate, dependencyTemplates, "/******/ "); source.add(this.applyPluginsWaterfall("modules", modules, chunk, hash, moduleTemplate, dependencyTemplates)); source.add(")"); return source; });
sources.forEach(function(source) { concat.add(compilation.assets[source]); concat.add('\n'); });
chunk.modules.forEach(function(module, idx) { if(idx != 0) source.add(",\n"); source.add("\n/***/ " + module.id + ":\n"); source.add(moduleTemplate.render(module, dependencyTemplates, chunk)); });
Template.prototype.renderChunkModules = function(chunk, moduleTemplate, dependencyTemplates, prefix) { if(!prefix) prefix = ""; var source = new ConcatSource(); if(chunk.modules.length === 0) { source.add("[]"); return source; } var bounds = this.getModulesArrayBounds(chunk.modules); if(bounds) { // Render a spare array var minId = bounds[0]; var maxId = bounds[1]; if(minId !== 0) source.add("Array(" + minId + ").concat("); source.add("[\n"); var modules = {}; chunk.modules.forEach(function(module) { modules[module.id] = module; }); for(var idx = minId; idx <= maxId; idx++) { var module = modules[idx]; if(idx !== minId) source.add(",\n"); source.add("/* " + idx + " */"); if(module) { source.add("\n"); source.add(moduleTemplate.render(module, dependencyTemplates, chunk)); } } source.add("\n" + prefix + "]"); if(minId !== 0) source.add(")"); } else { // Render an object source.add("{\n"); chunk.modules.slice().sort(function(a, b) { var aId = a.id + ""; var bId = b.id + ""; if(aId < bId) return -1; if(aId > bId) return 1; return 0; }).forEach(function(module, idx) { if(idx !== 0) source.add(",\n"); source.add("\n/***/ " + JSON.stringify(module.id) + ":\n"); source.add(moduleTemplate.render(module, dependencyTemplates, chunk)); }); source.add("\n\n" + prefix + "}"); } return source; };
}).forEach(function(module, idx) { if(idx !== 0) source.add(",\n"); source.add("\n/***/ " + JSON.stringify(module.id) + ":\n"); source.add(moduleTemplate.render(module, dependencyTemplates, chunk)); });
Template.prototype.renderChunkModules = function(chunk, moduleTemplate, dependencyTemplates, prefix) { if(!prefix) prefix = ""; var source = new ConcatSource(); if(chunk.modules.length === 0) { source.add("[]"); return source; } var maxId = chunk.modules[chunk.modules.length-1].id; var minId = chunk.modules[0].id; if(minId < 16 + (""+minId).length) { minId = 0; } var objectOverhead = chunk.modules.map(function(module) { return (module.id + "").length + 2; }).reduce(function(a, b) { return a + b }, -1); var arrayOverhead = minId === 0 ? maxId : 16 + (""+minId).length + maxId; if(arrayOverhead < objectOverhead) { // Render a sparse array if(minId !== 0) source.add("Array(" + minId + ").concat("); source.add("[\n"); var modules = {}; chunk.modules.forEach(function(module) { modules[module.id] = module; }); for(var idx = minId; idx <= maxId; idx++) { var module = modules[idx]; if(idx != minId) source.add(",\n"); source.add("/* " + idx + " */"); if(module) { source.add("\n"); source.add(moduleTemplate.render(module, dependencyTemplates, chunk)); } } source.add("\n" + prefix + "]"); if(minId !== 0) source.add(")"); } else { // Render an object source.add("{\n"); chunk.modules.forEach(function(module, idx) { if(idx != 0) source.add(",\n"); source.add("\n/***/ " + module.id + ":\n"); source.add(moduleTemplate.render(module, dependencyTemplates, chunk)); }); source.add("\n\n" + prefix + "}"); } return source; };