@@ -38,9 +38,21 @@ const accessorAccess = (base, accessor, joinWith = "; ") => {
3838 . join ( joinWith ) ;
3939} ;
4040
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+
4151/**
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
4456 */
4557
4658class UmdMainTemplatePlugin {
@@ -181,23 +193,27 @@ class UmdMainTemplatePlugin {
181193 amdFactory = "factory" ;
182194 }
183195
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+
184208 return new ConcatSource (
185209 new OriginalSource (
186210 "(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" ) +
192212 " if(typeof exports === 'object' && typeof module === 'object')\n" +
193213 " module.exports = factory(" +
194214 externalsRequireArray ( "commonjs2" ) +
195215 ");\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" ) +
201217 " else if(typeof define === 'function' && define.amd)\n" +
202218 ( requiredExternals . length > 0
203219 ? this . names . amd && this . namedDefine === true
@@ -221,24 +237,14 @@ class UmdMainTemplatePlugin {
221237 ");\n"
222238 : " define([], " + amdFactory + ");\n" ) +
223239 ( 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" ) +
230241 " else if(typeof exports === 'object')\n" +
231242 " exports[" +
232243 libraryName ( this . names . commonjs || this . names . root ) +
233244 "] = factory(" +
234245 externalsRequireArray ( "commonjs" ) +
235246 ");\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" ) +
242248 " else\n" +
243249 " " +
244250 replaceKeys (
0 commit comments