@@ -23,7 +23,17 @@ function accessorAccess(base, accessor) {
2323
2424class UmdMainTemplatePlugin {
2525 constructor ( name , options ) {
26- this . name = name ;
26+ if ( typeof name === "object" && ! Array . isArray ( name ) ) {
27+ this . name = name . root || name . amd || name . commonjs ;
28+ this . names = name ;
29+ } else {
30+ this . name = name ;
31+ this . names = {
32+ commonjs : name ,
33+ root : name ,
34+ amd : name
35+ } ;
36+ }
2737 this . optionalAmdExternalAsGlobal = options . optionalAmdExternalAsGlobal ;
2838 this . namedDefine = options . namedDefine ;
2939 this . auxiliaryComment = options . auxiliaryComment ;
@@ -124,16 +134,16 @@ class UmdMainTemplatePlugin {
124134 ) +
125135 " else if(typeof define === 'function' && define.amd)\n" +
126136 ( requiredExternals . length > 0 ?
127- ( this . name && this . namedDefine === true ?
128- " define(" + libraryName ( this . name ) + ", " + externalsDepsArray ( requiredExternals ) + ", " + amdFactory + ");\n" :
137+ ( this . names . amd && this . namedDefine === true ?
138+ " define(" + libraryName ( this . names . amd ) + ", " + externalsDepsArray ( requiredExternals ) + ", " + amdFactory + ");\n" :
129139 " define(" + externalsDepsArray ( requiredExternals ) + ", " + amdFactory + ");\n"
130140 ) :
131- ( this . name && this . namedDefine === true ?
132- " define(" + libraryName ( this . name ) + ", [], " + amdFactory + ");\n" :
141+ ( this . names . amd && this . namedDefine === true ?
142+ " define(" + libraryName ( this . names . amd ) + ", [], " + amdFactory + ");\n" :
133143 " define([], " + amdFactory + ");\n"
134144 )
135145 ) +
136- ( this . name ?
146+ ( this . names . root || this . names . commonjs ?
137147 ( this . auxiliaryComment &&
138148 typeof this . auxiliaryComment === "string" ?
139149 " //" + this . auxiliaryComment + "\n" :
@@ -142,7 +152,7 @@ class UmdMainTemplatePlugin {
142152 ""
143153 ) +
144154 " else if(typeof exports === 'object')\n" +
145- " exports[" + libraryName ( this . name ) + "] = factory(" + externalsRequireArray ( "commonjs" ) + ");\n" +
155+ " exports[" + libraryName ( this . names . commonjs || this . names . root ) + "] = factory(" + externalsRequireArray ( "commonjs" ) + ");\n" +
146156 ( this . auxiliaryComment &&
147157 typeof this . auxiliaryComment === "string" ?
148158 " //" + this . auxiliaryComment + "\n" :
@@ -151,7 +161,7 @@ class UmdMainTemplatePlugin {
151161 ""
152162 ) +
153163 " else\n" +
154- " " + replaceKeys ( accessorAccess ( "root" , this . name ) ) + " = factory(" + externalsRootArray ( externals ) + ");\n" :
164+ " " + replaceKeys ( accessorAccess ( "root" , this . names . root || this . names . commonjs ) ) + " = factory(" + externalsRootArray ( externals ) + ");\n" :
155165 " else {\n" +
156166 ( externals . length > 0 ?
157167 " var a = typeof exports === 'object' ? factory(" + externalsRequireArray ( "commonjs" ) + ") : factory(" + externalsRootArray ( externals ) + ");\n" :
@@ -163,12 +173,12 @@ class UmdMainTemplatePlugin {
163173 "})(this, function(" + externalsArguments ( externals ) + ") {\nreturn " , "webpack/universalModuleDefinition" ) , source , ";\n})" ) ;
164174 } . bind ( this ) ) ;
165175 mainTemplate . plugin ( "global-hash-paths" , function ( paths ) {
166- if ( this . name ) paths = paths . concat ( this . name ) ;
176+ if ( this . names . root ) paths = paths . concat ( this . names . root ) ;
167177 return paths ;
168178 } . bind ( this ) ) ;
169179 mainTemplate . plugin ( "hash" , function ( hash ) {
170180 hash . update ( "umd" ) ;
171- hash . update ( `${ this . name } ` ) ;
181+ hash . update ( `${ this . names . root } ` ) ;
172182 } . bind ( this ) ) ;
173183 }
174184}
0 commit comments