From bbff7403fbf46f9ad92240ac213df8d30ef31b64 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 20 Sep 2018 02:56:13 +0200 Subject: update packages --- node_modules/webpack/lib/AmdMainTemplatePlugin.js | 143 +++++++++++++--------- 1 file changed, 87 insertions(+), 56 deletions(-) (limited to 'node_modules/webpack/lib/AmdMainTemplatePlugin.js') diff --git a/node_modules/webpack/lib/AmdMainTemplatePlugin.js b/node_modules/webpack/lib/AmdMainTemplatePlugin.js index 727f49ba3..ff715ec6c 100644 --- a/node_modules/webpack/lib/AmdMainTemplatePlugin.js +++ b/node_modules/webpack/lib/AmdMainTemplatePlugin.js @@ -1,56 +1,87 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra - */ - -"use strict"; - -const ConcatSource = require("webpack-sources").ConcatSource; -const Template = require("./Template"); - -class AmdMainTemplatePlugin { - constructor(name) { - this.name = name; - } - - apply(compilation) { - const mainTemplate = compilation.mainTemplate; - - compilation.templatesPlugin("render-with-entry", (source, chunk, hash) => { - const externals = chunk.getModules().filter((m) => m.external); - const externalsDepsArray = JSON.stringify(externals.map((m) => - typeof m.request === "object" ? m.request.amd : m.request - )); - const externalsArguments = externals.map((m) => - Template.toIdentifier(`__WEBPACK_EXTERNAL_MODULE_${m.id}__`) - ).join(", "); - - if(this.name) { - const name = mainTemplate.applyPluginsWaterfall("asset-path", this.name, { - hash, - chunk - }); - - return new ConcatSource( - `define(${JSON.stringify(name)}, ${externalsDepsArray}, function(${externalsArguments}) { return `, source, "});" - ); - } else if(externalsArguments) { - return new ConcatSource(`define(${externalsDepsArray}, function(${externalsArguments}) { return `, source, "});"); - } else { - return new ConcatSource("define(function() { return ", source, "});"); - } - }); - - mainTemplate.plugin("global-hash-paths", (paths) => { - if(this.name) paths.push(this.name); - return paths; - }); - - mainTemplate.plugin("hash", (hash) => { - hash.update("exports amd"); - hash.update(this.name); - }); - } -} - -module.exports = AmdMainTemplatePlugin; +/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Tobias Koppers @sokra + */ + +"use strict"; + +const { ConcatSource } = require("webpack-sources"); +const Template = require("./Template"); + +/** @typedef {import("./Compilation")} Compilation */ + +class AmdMainTemplatePlugin { + /** + * @param {string} name the library name + */ + constructor(name) { + /** @type {string} */ + this.name = name; + } + + /** + * @param {Compilation} compilation the compilation instance + * @returns {void} + */ + apply(compilation) { + const { mainTemplate, chunkTemplate } = compilation; + + const onRenderWithEntry = (source, chunk, hash) => { + const externals = chunk.getModules().filter(m => m.external); + const externalsDepsArray = JSON.stringify( + externals.map( + m => (typeof m.request === "object" ? m.request.amd : m.request) + ) + ); + const externalsArguments = externals + .map( + m => `__WEBPACK_EXTERNAL_MODULE_${Template.toIdentifier(`${m.id}`)}__` + ) + .join(", "); + + if (this.name) { + const name = mainTemplate.getAssetPath(this.name, { + hash, + chunk + }); + + return new ConcatSource( + `define(${JSON.stringify( + name + )}, ${externalsDepsArray}, function(${externalsArguments}) { return `, + source, + "});" + ); + } else if (externalsArguments) { + return new ConcatSource( + `define(${externalsDepsArray}, function(${externalsArguments}) { return `, + source, + "});" + ); + } else { + return new ConcatSource("define(function() { return ", source, "});"); + } + }; + + for (const template of [mainTemplate, chunkTemplate]) { + template.hooks.renderWithEntry.tap( + "AmdMainTemplatePlugin", + onRenderWithEntry + ); + } + + mainTemplate.hooks.globalHashPaths.tap("AmdMainTemplatePlugin", paths => { + if (this.name) { + paths.push(this.name); + } + return paths; + }); + + mainTemplate.hooks.hash.tap("AmdMainTemplatePlugin", hash => { + hash.update("exports amd"); + hash.update(this.name); + }); + } +} + +module.exports = AmdMainTemplatePlugin; -- cgit v1.2.3