@@ -38,9 +38,21 @@ const accessorAccess = (base, accessor, joinWith = "; ") => {
38
38
. join ( joinWith ) ;
39
39
} ;
40
40
41
+ /** @typedef {string | string[] | Record<string, string | string[]> } UmdMainTemplatePluginName */
42
+
43
+ /**
44
+ * @typedef {Object } AuxiliaryCommentObject
45
+ * @property {string } root
46
+ * @property {string } commonjs
47
+ * @property {string } commonjs2
48
+ * @property {string } amd
49
+ */
50
+
41
51
/**
42
- * @typedef {string | string[] | {[k: string]: string | string[]} } UmdMainTemplatePluginName
43
- * @typedef {{optionalAmdExternalAsGlobal: boolean, namedDefine: boolean, auxiliaryComment: TODO} } UmdMainTemplatePluginOption
52
+ * @typedef {Object } UmdMainTemplatePluginOption
53
+ * @property {boolean= } optionalAmdExternalAsGlobal
54
+ * @property {boolean } namedDefine
55
+ * @property {string | AuxiliaryCommentObject } auxiliaryComment
44
56
*/
45
57
46
58
class UmdMainTemplatePlugin {
@@ -181,23 +193,27 @@ class UmdMainTemplatePlugin {
181
193
amdFactory = "factory" ;
182
194
}
183
195
196
+ const auxiliaryComment = this . auxiliaryComment ;
197
+
198
+ const getAuxilaryComment = type => {
199
+ if ( auxiliaryComment ) {
200
+ if ( typeof auxiliaryComment === "string" )
201
+ return "\t//" + auxiliaryComment + "\n" ;
202
+ if ( auxiliaryComment [ type ] )
203
+ return "\t//" + auxiliaryComment [ type ] + "\n" ;
204
+ }
205
+ return "" ;
206
+ } ;
207
+
184
208
return new ConcatSource (
185
209
new OriginalSource (
186
210
"(function webpackUniversalModuleDefinition(root, factory) {\n" +
187
- ( this . auxiliaryComment && typeof this . auxiliaryComment === "string"
188
- ? " //" + this . auxiliaryComment + "\n"
189
- : this . auxiliaryComment . commonjs2
190
- ? " //" + this . auxiliaryComment . commonjs2 + "\n"
191
- : "" ) +
211
+ getAuxilaryComment ( "commonjs2" ) +
192
212
" if(typeof exports === 'object' && typeof module === 'object')\n" +
193
213
" module.exports = factory(" +
194
214
externalsRequireArray ( "commonjs2" ) +
195
215
");\n" +
196
- ( this . auxiliaryComment && typeof this . auxiliaryComment === "string"
197
- ? " //" + this . auxiliaryComment + "\n"
198
- : this . auxiliaryComment . amd
199
- ? " //" + this . auxiliaryComment . amd + "\n"
200
- : "" ) +
216
+ getAuxilaryComment ( "amd" ) +
201
217
" else if(typeof define === 'function' && define.amd)\n" +
202
218
( requiredExternals . length > 0
203
219
? this . names . amd && this . namedDefine === true
@@ -221,24 +237,14 @@ class UmdMainTemplatePlugin {
221
237
");\n"
222
238
: " define([], " + amdFactory + ");\n" ) +
223
239
( this . names . root || this . names . commonjs
224
- ? ( this . auxiliaryComment &&
225
- typeof this . auxiliaryComment === "string"
226
- ? " //" + this . auxiliaryComment + "\n"
227
- : this . auxiliaryComment . commonjs
228
- ? " //" + this . auxiliaryComment . commonjs + "\n"
229
- : "" ) +
240
+ ? getAuxilaryComment ( "commonjs" ) +
230
241
" else if(typeof exports === 'object')\n" +
231
242
" exports[" +
232
243
libraryName ( this . names . commonjs || this . names . root ) +
233
244
"] = factory(" +
234
245
externalsRequireArray ( "commonjs" ) +
235
246
");\n" +
236
- ( this . auxiliaryComment &&
237
- typeof this . auxiliaryComment === "string"
238
- ? " //" + this . auxiliaryComment + "\n"
239
- : this . auxiliaryComment . root
240
- ? " //" + this . auxiliaryComment . root + "\n"
241
- : "" ) +
247
+ getAuxilaryComment ( "root" ) +
242
248
" else\n" +
243
249
" " +
244
250
replaceKeys (
0 commit comments