@@ -32,13 +32,28 @@ define(function(require, exports) {
32
32
33
33
var settings = configure ( config ) ;
34
34
35
- // Builds must happen with Node.
35
+ // Builds with r.js require Node.js to be installed .
36
36
if ( config . isBuild ) {
37
37
var path = settings . root + name + settings . ext ;
38
+ var contents = "" ;
39
+
40
+ try {
41
+ // First try reading the filepath as-is.
42
+ contents = String ( fs . readFileSync ( path ) ) ;
43
+ } catch ( ex ) {
44
+ // If it failed, it's most likely because of a leading `/` and not an
45
+ // absolute path. Remove the leading slash and try again.
46
+ if ( path [ 0 ] === "/" ) {
47
+ path = path . slice ( 1 ) ;
48
+ }
49
+
50
+ // Try reading again with the leading `/`.
51
+ contents = String ( fs . readFileSync ( path ) ) ;
52
+ }
38
53
39
54
// Read in the file synchronously, as RequireJS expects, and return the
40
55
// contents. Process as a Lo-Dash template.
41
- buildMap [ name ] = _ . template ( String ( fs . readFileSync ( path ) ) ) ;
56
+ buildMap [ name ] = _ . template ( contents ) ;
42
57
43
58
return load ( ) ;
44
59
}
@@ -58,7 +73,7 @@ define(function(require, exports) {
58
73
} ;
59
74
60
75
// Initiate the fetch.
61
- xhr . open ( "GET" , "/" + settings . root + name + settings . ext , true ) ;
76
+ xhr . open ( "GET" , settings . root + name + settings . ext , true ) ;
62
77
xhr . send ( null ) ;
63
78
} ;
64
79
@@ -106,6 +121,11 @@ define(function(require, exports) {
106
121
templateSettings : { }
107
122
} , config . lodashLoader ) ;
108
123
124
+ // Ensure the root has been properly configured with a trailing slash.
125
+ if ( settings . root [ settings . root . length - 1 ] !== "/" ) {
126
+ settings . root += "/" ;
127
+ }
128
+
109
129
// Set the custom passed in template settings.
110
130
_ . extend ( _ . templateSettings , settings . templateSettings ) ;
111
131
0 commit comments