@@ -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 ;
@@ -125,16 +135,16 @@ class UmdMainTemplatePlugin {
125135 ) +
126136 " else if(typeof define === 'function' && define.amd)\n" +
127137 ( requiredExternals . length > 0 ?
128- ( this . name && this . namedDefine === true ?
129- " define(" + libraryName ( this . name ) + ", " + externalsDepsArray ( requiredExternals ) + ", " + amdFactory + ");\n" :
138+ ( this . names . amd && this . namedDefine === true ?
139+ " define(" + libraryName ( this . names . amd ) + ", " + externalsDepsArray ( requiredExternals ) + ", " + amdFactory + ");\n" :
130140 " define(" + externalsDepsArray ( requiredExternals ) + ", " + amdFactory + ");\n"
131141 ) :
132- ( this . name && this . namedDefine === true ?
133- " define(" + libraryName ( this . name ) + ", [], " + amdFactory + ");\n" :
142+ ( this . names . amd && this . namedDefine === true ?
143+ " define(" + libraryName ( this . names . amd ) + ", [], " + amdFactory + ");\n" :
134144 " define([], " + amdFactory + ");\n"
135145 )
136146 ) +
137- ( this . name ?
147+ ( this . names . root || this . names . commonjs ?
138148 ( this . auxiliaryComment &&
139149 typeof this . auxiliaryComment === "string" ?
140150 " //" + this . auxiliaryComment + "\n" :
@@ -143,7 +153,7 @@ class UmdMainTemplatePlugin {
143153 ""
144154 ) +
145155 " else if(typeof exports === 'object')\n" +
146- " exports[" + libraryName ( this . name ) + "] = factory(" + externalsRequireArray ( "commonjs" ) + ");\n" +
156+ " exports[" + libraryName ( this . names . commonjs || this . names . root ) + "] = factory(" + externalsRequireArray ( "commonjs" ) + ");\n" +
147157 ( this . auxiliaryComment &&
148158 typeof this . auxiliaryComment === "string" ?
149159 " //" + this . auxiliaryComment + "\n" :
@@ -152,7 +162,7 @@ class UmdMainTemplatePlugin {
152162 ""
153163 ) +
154164 " else\n" +
155- " " + replaceKeys ( accessorAccess ( "root" , this . name ) ) + " = factory(" + externalsRootArray ( externals ) + ");\n" :
165+ " " + replaceKeys ( accessorAccess ( "root" , this . names . root || this . names . commonjs ) ) + " = factory(" + externalsRootArray ( externals ) + ");\n" :
156166 " else {\n" +
157167 ( externals . length > 0 ?
158168 " var a = typeof exports === 'object' ? factory(" + externalsRequireArray ( "commonjs" ) + ") : factory(" + externalsRootArray ( externals ) + ");\n" :
@@ -164,12 +174,16 @@ class UmdMainTemplatePlugin {
164174 "})(this, function(" + externalsArguments ( externals ) + ") {\nreturn " , "webpack/universalModuleDefinition" ) , source , ";\n})" ) ;
165175 } . bind ( this ) ) ;
166176 mainTemplate . plugin ( "global-hash-paths" , function ( paths ) {
167- if ( this . name ) paths = paths . concat ( this . name ) ;
177+ if ( this . names . root ) paths = paths . concat ( this . names . root ) ;
178+ if ( this . names . amd ) paths = paths . concat ( this . names . amd ) ;
179+ if ( this . names . commonjs ) paths = paths . concat ( this . names . commonjs ) ;
168180 return paths ;
169181 } . bind ( this ) ) ;
170182 mainTemplate . plugin ( "hash" , function ( hash ) {
171183 hash . update ( "umd" ) ;
172- hash . update ( `${ this . name } ` ) ;
184+ hash . update ( `${ this . names . root } ` ) ;
185+ hash . update ( `${ this . names . amd } ` ) ;
186+ hash . update ( `${ this . names . commonjs } ` ) ;
173187 } . bind ( this ) ) ;
174188 }
175189}
0 commit comments