@@ -20,9 +20,10 @@ function accessorAccess(base, accessor) {
2020 } ) . join ( ", " ) ;
2121}
2222
23- function UmdMainTemplatePlugin ( name , optionalAmdExternalAsGlobal ) {
23+ function UmdMainTemplatePlugin ( name , options ) {
2424 this . name = name ;
25- this . optionalAmdExternalAsGlobal = optionalAmdExternalAsGlobal ;
25+ this . optionalAmdExternalAsGlobal = options . optionalAmdExternalAsGlobal ;
26+ this . namedDefine = options . namedDefine ;
2627}
2728module . exports = UmdMainTemplatePlugin ;
2829UmdMainTemplatePlugin . prototype . apply = function ( compilation ) {
@@ -87,6 +88,11 @@ UmdMainTemplatePlugin.prototype.apply = function(compilation) {
8788 return "__WEBPACK_EXTERNAL_MODULE_" + m . id + "__" ;
8889 } ) . join ( ", " ) ;
8990 }
91+
92+ function libraryName ( library ) {
93+ return JSON . stringify ( replaceKeys ( [ ] . concat ( library ) . pop ( ) ) ) ;
94+ }
95+
9096 if ( optionalExternals . length > 0 ) {
9197 var amdFactory = "function webpackLoadOptionalExternalModuleAmd(" + externalsArguments ( requiredExternals ) + ") {\n" +
9298 " return factory(" + (
@@ -98,18 +104,25 @@ UmdMainTemplatePlugin.prototype.apply = function(compilation) {
98104 } else {
99105 var amdFactory = "factory" ;
100106 }
107+
101108 return new ConcatSource ( new OriginalSource (
102109 "(function webpackUniversalModuleDefinition(root, factory) {\n" +
103110 " if(typeof exports === 'object' && typeof module === 'object')\n" +
104111 " module.exports = factory(" + externalsRequireArray ( "commonjs2" ) + ");\n" +
105112 " else if(typeof define === 'function' && define.amd)\n" +
106113 ( requiredExternals . length > 0 ?
107- " define(" + externalsDepsArray ( requiredExternals ) + ", " + amdFactory + ");\n" :
108- " define([], " + amdFactory + ");\n"
114+ ( this . name && this . namedDefine === true ?
115+ " define(" + libraryName ( this . name ) + ", " + externalsDepsArray ( requiredExternals ) + ", " + amdFactory + ");\n" :
116+ " define(" + externalsDepsArray ( requiredExternals ) + ", " + amdFactory + ");\n"
117+ ) :
118+ ( this . name && this . namedDefine === true ?
119+ " define(" + libraryName ( this . name ) + ", [], " + amdFactory + ");\n" :
120+ " define([], " + amdFactory + ");\n"
121+ )
109122 ) +
110123 ( this . name ?
111124 " else if(typeof exports === 'object')\n" +
112- " exports[" + JSON . stringify ( replaceKeys ( [ ] . concat ( this . name ) . pop ( ) ) ) + "] = factory(" + externalsRequireArray ( "commonjs" ) + ");\n" +
125+ " exports[" + libraryName ( this . name ) + "] = factory(" + externalsRequireArray ( "commonjs" ) + ");\n" +
113126 " else\n" +
114127 " " + replaceKeys ( accessorAccess ( "root" , this . name ) ) + " = factory(" + externalsRootArray ( externals ) + ");\n" :
115128 " else {\n" +
0 commit comments