@@ -29,6 +29,7 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
2929/**
3030 * @typedef {Object } AmdLibraryPluginParsed
3131 * @property {string } name
32+ * @property {string } amdContainer
3233 */
3334
3435/**
@@ -52,7 +53,7 @@ class AmdLibraryPlugin extends AbstractLibraryPlugin {
5253 * @returns {T | false } preprocess as needed by overriding
5354 */
5455 parseOptions ( library ) {
55- const { name } = library ;
56+ const { name, amdContainer } = library ;
5657 if ( this . requireAsWrapper ) {
5758 if ( name ) {
5859 throw new Error (
@@ -67,7 +68,8 @@ class AmdLibraryPlugin extends AbstractLibraryPlugin {
6768 }
6869 }
6970 return {
70- name : /** @type {string= } */ ( name )
71+ name : /** @type {string= } */ ( name ) ,
72+ amdContainer : /** @type {string= } */ ( amdContainer )
7173 } ;
7274 }
7375
@@ -111,9 +113,14 @@ class AmdLibraryPlugin extends AbstractLibraryPlugin {
111113 ( iife || ! chunk . hasRuntime ( ) ? " return " : "\n" ) ;
112114 const fnEnd = iife ? ";\n}" : "\n}" ;
113115
116+ let amdContainerPrefix = "" ;
117+ if ( options . amdContainer ) {
118+ amdContainerPrefix = `${ options . amdContainer } .` ;
119+ }
120+
114121 if ( this . requireAsWrapper ) {
115122 return new ConcatSource (
116- `require(${ externalsDepsArray } , ${ fnStart } ` ,
123+ `${ amdContainerPrefix } require(${ externalsDepsArray } , ${ fnStart } ` ,
117124 source ,
118125 `${ fnEnd } );`
119126 ) ;
@@ -123,18 +130,24 @@ class AmdLibraryPlugin extends AbstractLibraryPlugin {
123130 } ) ;
124131
125132 return new ConcatSource (
126- `define(${ JSON . stringify ( name ) } , ${ externalsDepsArray } , ${ fnStart } ` ,
133+ `${ amdContainerPrefix } define(${ JSON . stringify (
134+ name
135+ ) } , ${ externalsDepsArray } , ${ fnStart } `,
127136 source ,
128137 `${ fnEnd } );`
129138 ) ;
130139 } else if ( externalsArguments ) {
131140 return new ConcatSource (
132- `define(${ externalsDepsArray } , ${ fnStart } ` ,
141+ `${ amdContainerPrefix } define(${ externalsDepsArray } , ${ fnStart } ` ,
133142 source ,
134143 `${ fnEnd } );`
135144 ) ;
136145 } else {
137- return new ConcatSource ( `define(${ fnStart } ` , source , `${ fnEnd } );` ) ;
146+ return new ConcatSource (
147+ `${ amdContainerPrefix } define(${ fnStart } ` ,
148+ source ,
149+ `${ fnEnd } );`
150+ ) ;
138151 }
139152 }
140153
@@ -155,6 +168,9 @@ class AmdLibraryPlugin extends AbstractLibraryPlugin {
155168 chunk
156169 } ) ;
157170 hash . update ( name ) ;
171+ } else if ( options . amdContainer ) {
172+ hash . update ( "amdContainer" ) ;
173+ hash . update ( options . amdContainer ) ;
158174 }
159175 }
160176}
0 commit comments