@@ -123,6 +123,9 @@ module.exports = class DojoAMDMainTemplatePlugin {
123123 }
124124
125125 compilation . mainTemplate . plugin ( "bootstrap" , function ( source , chunk ) {
126+ if ( ! compilation . dojoLoaderDependenciesAdded ) {
127+ return source ;
128+ }
126129 const buf = [ ] ;
127130 const jsonpFunction = this . outputOptions . jsonpFunction || Template . toIdentifier ( "webpackJsonp" + ( this . outputOptions . library || "" ) ) ;
128131 buf . push ( source ) ;
@@ -183,14 +186,17 @@ module.exports = class DojoAMDMainTemplatePlugin {
183186 return this . asString ( buf ) ;
184187 } ) ;
185188
186- compilation . mainTemplate . plugin ( "module-obj" , function ( ) {
187- return this . asString ( [
188- "i: req.absMidsById[moduleId] || moduleId," ,
189- "exports: {}"
190- ] ) ;
189+ compilation . mainTemplate . plugin ( "module-obj" , function ( source ) {
190+ if ( compilation . dojoLoaderDependenciesAdded ) {
191+ source = source . replace ( "i: moduleId," , "i: req.absMidsById[moduleId] || moduleId,") ;
192+ }
193+ return source ;
191194 } ) ;
192195
193196 compilation . mainTemplate . plugin ( "require-extensions" , function ( source ) {
197+ if ( ! compilation . dojoLoaderDependenciesAdded ) {
198+ return source ;
199+ }
194200 const buf = [ ] ;
195201 buf . push ( source ) ;
196202 buf . push ( "" ) ;
@@ -202,13 +208,14 @@ module.exports = class DojoAMDMainTemplatePlugin {
202208 buf . push ( "\tg: (function(){return this;})() // Easy access to global scope" ) ;
203209 buf . push ( "};" ) ;
204210 buf . push ( "var loaderScope = {document:document};" ) ;
205- const dojoLoaderModule = compilation . findModule ( require . resolve ( options . loader ) ) ;
211+ const modules = compilation . getModules ? compilation . getModules ( ) : compilation . modules ;
212+ const dojoLoaderModule = modules . find ( ( module ) => { return module . rawRequest === options . loader ; } ) ;
206213 if ( ! dojoLoaderModule ) {
207214 throw Error ( "Can't locate " + options . loader + " in compilation" ) ;
208215 }
209216 var s = "var loaderConfig = " ;
210217 if ( util . isString ( options . loaderConfig ) ) {
211- const dojoLoaderConfig = compilation . findModule ( require . resolve ( options . loaderConfig ) ) ;
218+ const dojoLoaderConfig = modules . find ( ( module ) => { return module . rawRequest === options . loaderConfig ; } ) ;
212219 s += this . requireFn + "(" + JSON . stringify ( dojoLoaderConfig . id ) + ");" ;
213220 } else {
214221 s += JSON . stringify ( options . loaderConfig ) ;
@@ -225,10 +232,12 @@ module.exports = class DojoAMDMainTemplatePlugin {
225232 } ) ;
226233
227234 compilation . mainTemplate . plugin ( "hash" , function ( hash ) {
228- hash . update ( "DojoAMDMainTemplate" ) ;
229- hash . update ( "2" ) ; // Increment this whenever the template code above changes
230- if ( ! util . isString ( options . loaderConfig ) ) {
231- hash . update ( JSON . stringify ( options . loaderConfig ) ) ;
235+ if ( compilation . dojoLoaderDependenciesAdded ) {
236+ hash . update ( "DojoAMDMainTemplate" ) ;
237+ hash . update ( "3" ) ; // Increment this whenever the template code above changes
238+ if ( ! util . isString ( options . loaderConfig ) ) {
239+ hash . update ( JSON . stringify ( options . loaderConfig ) ) ;
240+ }
232241 }
233242 } ) ;
234243 }
0 commit comments