From 363723fc84f7b8477592e0105aeb331ec9a017af Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 14 Aug 2017 05:01:11 +0200 Subject: node_modules --- node_modules/webpack/lib/UmdMainTemplatePlugin.js | 49 +++++++++++++++-------- 1 file changed, 32 insertions(+), 17 deletions(-) (limited to 'node_modules/webpack/lib/UmdMainTemplatePlugin.js') diff --git a/node_modules/webpack/lib/UmdMainTemplatePlugin.js b/node_modules/webpack/lib/UmdMainTemplatePlugin.js index 81873305a..3ddb98d23 100644 --- a/node_modules/webpack/lib/UmdMainTemplatePlugin.js +++ b/node_modules/webpack/lib/UmdMainTemplatePlugin.js @@ -23,7 +23,17 @@ function accessorAccess(base, accessor) { class UmdMainTemplatePlugin { constructor(name, options) { - this.name = name; + if(typeof name === "object" && !Array.isArray(name)) { + this.name = name.root || name.amd || name.commonjs; + this.names = name; + } else { + this.name = name; + this.names = { + commonjs: name, + root: name, + amd: name + }; + } this.optionalAmdExternalAsGlobal = options.optionalAmdExternalAsGlobal; this.namedDefine = options.namedDefine; this.auxiliaryComment = options.auxiliaryComment; @@ -31,8 +41,8 @@ class UmdMainTemplatePlugin { apply(compilation) { const mainTemplate = compilation.mainTemplate; - compilation.templatesPlugin("render-with-entry", function(source, chunk, hash) { - let externals = chunk.modules.filter(m => m.external); + compilation.templatesPlugin("render-with-entry", (source, chunk, hash) => { + let externals = chunk.getModules().filter(m => m.external); const optionalExternals = []; let requiredExternals = []; if(this.optionalAmdExternalAsGlobal) { @@ -72,6 +82,7 @@ class UmdMainTemplatePlugin { let expr; let request = m.request; if(typeof request === "object") request = request[type]; + if(typeof request === "undefined") throw new Error("Missing external configuration for type:" + type); if(Array.isArray(request)) { expr = `require(${JSON.stringify(request[0])})${accessorToObjectAccess(request.slice(1))}`; } else @@ -124,16 +135,16 @@ class UmdMainTemplatePlugin { ) + " else if(typeof define === 'function' && define.amd)\n" + (requiredExternals.length > 0 ? - (this.name && this.namedDefine === true ? - " define(" + libraryName(this.name) + ", " + externalsDepsArray(requiredExternals) + ", " + amdFactory + ");\n" : + (this.names.amd && this.namedDefine === true ? + " define(" + libraryName(this.names.amd) + ", " + externalsDepsArray(requiredExternals) + ", " + amdFactory + ");\n" : " define(" + externalsDepsArray(requiredExternals) + ", " + amdFactory + ");\n" ) : - (this.name && this.namedDefine === true ? - " define(" + libraryName(this.name) + ", [], " + amdFactory + ");\n" : + (this.names.amd && this.namedDefine === true ? + " define(" + libraryName(this.names.amd) + ", [], " + amdFactory + ");\n" : " define([], " + amdFactory + ");\n" ) ) + - (this.name ? + (this.names.root || this.names.commonjs ? (this.auxiliaryComment && typeof this.auxiliaryComment === "string" ? " //" + this.auxiliaryComment + "\n" : @@ -142,7 +153,7 @@ class UmdMainTemplatePlugin { "" ) + " else if(typeof exports === 'object')\n" + - " exports[" + libraryName(this.name) + "] = factory(" + externalsRequireArray("commonjs") + ");\n" + + " exports[" + libraryName(this.names.commonjs || this.names.root) + "] = factory(" + externalsRequireArray("commonjs") + ");\n" + (this.auxiliaryComment && typeof this.auxiliaryComment === "string" ? " //" + this.auxiliaryComment + "\n" : @@ -151,7 +162,7 @@ class UmdMainTemplatePlugin { "" ) + " else\n" + - " " + replaceKeys(accessorAccess("root", this.name)) + " = factory(" + externalsRootArray(externals) + ");\n" : + " " + replaceKeys(accessorAccess("root", this.names.root || this.names.commonjs)) + " = factory(" + externalsRootArray(externals) + ");\n" : " else {\n" + (externals.length > 0 ? " var a = typeof exports === 'object' ? factory(" + externalsRequireArray("commonjs") + ") : factory(" + externalsRootArray(externals) + ");\n" : @@ -161,15 +172,19 @@ class UmdMainTemplatePlugin { " }\n" ) + "})(this, function(" + externalsArguments(externals) + ") {\nreturn ", "webpack/universalModuleDefinition"), source, ";\n})"); - }.bind(this)); - mainTemplate.plugin("global-hash-paths", function(paths) { - if(this.name) paths = paths.concat(this.name); + }); + mainTemplate.plugin("global-hash-paths", (paths) => { + if(this.names.root) paths = paths.concat(this.names.root); + if(this.names.amd) paths = paths.concat(this.names.amd); + if(this.names.commonjs) paths = paths.concat(this.names.commonjs); return paths; - }.bind(this)); - mainTemplate.plugin("hash", function(hash) { + }); + mainTemplate.plugin("hash", (hash) => { hash.update("umd"); - hash.update(`${this.name}`); - }.bind(this)); + hash.update(`${this.names.root}`); + hash.update(`${this.names.amd}`); + hash.update(`${this.names.commonjs}`); + }); } } -- cgit v1.2.3