@@ -46,7 +46,6 @@ module.exports = class DojoAMDMainTemplatePlugin {
46
46
} ) ;
47
47
compilation . plugin ( "before-chunk-assets" , this . relativizeAbsoluteAbsMids . bind ( context ) ) ;
48
48
plugin ( compilation . mainTemplate , {
49
- "bootstrap" : this . bootstrap ,
50
49
"require-extensions" : this . requireExtensions ,
51
50
"dojo-require-extensions" : this . dojoRequireExtensions , // plugin specific event
52
51
"render-dojo-config-vars" : this . renderDojoConfigVars , // plugin specific event
@@ -67,11 +66,14 @@ module.exports = class DojoAMDMainTemplatePlugin {
67
66
this . embeddedLoaderHasConfigApi = ! ! scope . require . packs ;
68
67
}
69
68
70
- bootstrap ( source , chunk ) {
71
- const buf = [ ] ;
69
+ requireExtensions ( ...args ) {
70
+ return this . compilation . mainTemplate . applyPluginsWaterfall ( "dojo-require-extensions" , ...args ) ; // plugin specific event
71
+ }
72
+
73
+ dojoRequireExtensions ( source , chunk , ...rest ) {
72
74
const { mainTemplate} = this . compilation ;
73
75
const runtimeSource = Template . getFunctionContent ( require ( "./DojoAMDMainTemplate.runtime.js" ) . main ) ;
74
- buf . push ( source ) ;
76
+ const buf = [ ] ;
75
77
buf . push ( runtimeSource ) ;
76
78
buf . push ( "req.toUrl = toUrl;" ) ;
77
79
buf . push ( "req.toAbsMid = toAbsMid;" ) ;
@@ -89,22 +91,12 @@ module.exports = class DojoAMDMainTemplatePlugin {
89
91
buf . push ( mainTemplate . indent ( `(this||window)[${ jsonpFn } ].registerAbsMids = registerAbsMids;` ) ) ;
90
92
}
91
93
buf . push ( "})();" ) ;
92
- return mainTemplate . asString ( buf ) ;
93
- }
94
-
95
- requireExtensions ( ...args ) {
96
- return this . compilation . mainTemplate . applyPluginsWaterfall ( "dojo-require-extensions" , ...args ) ; // plugin specific event
97
- }
98
-
99
- dojoRequireExtensions ( source , ...rest ) {
100
- const { mainTemplate} = this . compilation ;
101
- const buf = [ ] ;
102
- buf . push ( source ) ;
103
94
buf . push ( "" ) ;
104
95
buf . push ( "// expose the Dojo compatibility functions as a properties of " + mainTemplate . requireFn ) ;
105
96
buf . push ( "var globalScope = (function(){return this||window;})();" ) ;
106
97
buf . push ( mainTemplate . requireFn + ".dj = {" ) ;
107
98
buf . push ( mainTemplate . indent ( [
99
+ "r: req," ,
108
100
"c: createContextRequire," ,
109
101
"m: dojoModuleFromWebpackModule," ,
110
102
"h: resolveTernaryHasExpression," ,
@@ -131,10 +123,8 @@ module.exports = class DojoAMDMainTemplatePlugin {
131
123
but the loader specified at ${ this . embeddedLoaderFilename } was built without the config API. Please rebuild the embedded loader with 'dojo-config-api' feature enabled` ) ;
132
124
}
133
125
}
134
- buf . push ( mainTemplate . applyPluginsWaterfall ( "render-dojo-config-vars" , loaderScope , "" , ...rest ) ) ;
135
- if ( this . buildContext ) {
136
- buf . push ( `loaderScope.buildContext = "${ this . buildContext } "` ) ;
137
- }
126
+ buf . push ( mainTemplate . applyPluginsWaterfall ( "render-dojo-config-vars" , loaderScope , "" , chunk , ...rest ) ) ;
127
+ buf . push ( `var globalRequireContext = "${ this . globalRequireContext || 'null' } "` ) ;
138
128
buf . push ( "var dojoLoader = " + mainTemplate . requireFn + "(" + JSON . stringify ( dojoLoaderModule . id ) + ");" ) ;
139
129
buf . push ( "dojoLoader.call(loaderScope, userConfig, defaultConfig, loaderScope, loaderScope);" ) ;
140
130
if ( loaderScope ) {
@@ -148,11 +138,15 @@ but the loader specified at ${this.embeddedLoaderFilename} was built without the
148
138
buf . push ( "req.signal = loaderScope.require.signal" ) ;
149
139
const loaderConfig = this . compiler . applyPluginsBailResult ( "get dojo config" ) ;
150
140
if ( loaderConfig . has && loaderConfig . has [ 'dojo-undef-api' ] ) {
151
- const undefSource = Template . getFunctionContent ( require ( "./DojoAMDMainTemplate.runtime.js" ) . undef ) ;
152
- buf . push ( "req.undef = " + undefSource ) ;
141
+ buf . push ( "req.undef = " + Template . getFunctionContent ( require ( "./DojoAMDMainTemplate.runtime.js" ) . undef ) ) ;
153
142
}
154
- buf . push ( "" ) ;
155
- return mainTemplate . asString ( buf ) ;
143
+ return mainTemplate . asString ( [
144
+ source ,
145
+ "(function() {" ,
146
+ mainTemplate . indent ( buf ) ,
147
+ "})();" ,
148
+ "var req=" + Template . getFunctionContent ( require ( "./DojoAMDMainTemplate.runtime.js" ) . makeDeprecatedReq )
149
+ ] ) ;
156
150
}
157
151
158
152
renderDojoConfigVars ( loaderScope ) {
@@ -224,20 +218,20 @@ but the loader specified at ${this.embeddedLoaderFilename} was built without the
224
218
* They have the form '$$root$$/<absolute-path>' where '$$root$$' can be changed using the globalContext.varName
225
219
* option. So as not to expose absolute paths on the client for security reasons, we determine the closest common
226
220
* directory for all the absolute absMids and rewrite the absMids in the form '$$root$$/<relative-path>', where the
227
- * path is relative to the buildContext path, and the buildContext path is calculated as the globalContext
221
+ * path is relative to the globalRequireContext path, and the globalRequireContext path is calculated as the globalContext
228
222
* directory relative to the closest common directory. For example, if the globalContext path is '/a/b/c/d/e'
229
- * and the closest common directory is '/a/b/c', then the buildContext path would be'$$root$$/d/e', and the
223
+ * and the closest common directory is '/a/b/c', then the globalRequireContext path would be'$$root$$/d/e', and the
230
224
* modified absMid for the module with absolute absMid '$$root$$/a/b/c/d/f/foo' would be '$$root$$/d/f/foo'. The
231
- * buildContext path is emitted to the client so that runtime global require calls specifying relative module ids
225
+ * globalRequireContext path is emitted to the client so that runtime global require calls specifying relative module ids
232
226
* can be resolved on the client. If at runtime, the client calls global require with the module id '../f/foo',
233
- * then the absMid for the module will be computed by resolving the specified module id against the buildContext
227
+ * then the absMid for the module will be computed by resolving the specified module id against the globalRequireContext
234
228
* path ('$$root$$/d/e'), resulting in '$$root$$/d/f/foo' and the client will locate the module by looking
235
229
* it up in the table of registered absMids.
236
230
*
237
- * In the event that runtime global require calls attempt to traverse the buildContext parent hierarchy
231
+ * In the event that runtime global require calls attempt to traverse the globalRequireContext parent hierarchy
238
232
* beyond the level of the closest common directory, the globalContext.numParents option can be specified
239
233
* to indicate the number of parent directories beyond the closest common directory to include in
240
- * the buildContext path. In the example above, a numParents value of 1 would result in the buildContext
234
+ * the globalRequireContext path. In the example above, a numParents value of 1 would result in the globalRequireContext
241
235
* path changing from '$$root$$/d/e' to '$$root$$/c/d/e' and the absMid for the module with absolute path
242
236
* '/a/b/c/d/f/foo' changing from '$$root$$/d/f/foo' to '$$root$$/c/d/f/foo'.
243
237
*/
@@ -273,9 +267,9 @@ but the loader specified at ${this.embeddedLoaderFilename} was built without the
273
267
// Determine the relative path from the adjusted common root to the global context and set it
274
268
// as the build context that gets adorned and emitted to the client.
275
269
var relative = path . relative ( commonRoot , context ) ;
276
- this . buildContext = path . join ( rootVarName , relative ) . replace ( / \\ / g, '/' ) ;
277
- if ( ! this . buildContext . endsWith ( '/' ) ) {
278
- this . buildContext += '/' ;
270
+ this . globalRequireContext = path . join ( rootVarName , relative ) . replace ( / \\ / g, '/' ) ;
271
+ if ( ! this . globalRequireContext . endsWith ( '/' ) ) {
272
+ this . globalRequireContext += '/' ;
279
273
}
280
274
// Now rewrite the absMids to be relative to the computed build context
281
275
relMods . forEach ( module => {
0 commit comments