1- var fetchText = function ( url , callback ) {
2- var xhr = new XMLHttpRequest ( ) ;
3- xhr . open ( 'GET' , url , true ) ;
4- xhr . onreadystatechange = function ( evt ) {
5- //Do not explicitly handle errors, those should be
6- //visible via console output in the browser.
7- if ( xhr . readyState === 4 ) {
8- callback ( xhr . responseText ) ;
9- }
1+ var getXhr , fetchText , _buildMap = { } ;
2+
3+ if ( typeof window !== "undefined" && window . navigator && window . document ) {
4+ getXhr = function ( ) {
5+ return new XMLHttpRequest ( ) ;
106 } ;
11- xhr . send ( null ) ;
12- } ;
7+
8+ fetchText = function ( url , callback ) {
9+ var xhr = getXhr ( ) ;
10+ xhr . open ( 'GET' , url , true ) ;
11+ xhr . onreadystatechange = function ( evt ) {
12+ //Do not explicitly handle errors, those should be
13+ //visible via console output in the browser.
14+ if ( xhr . readyState === 4 ) {
15+ callback ( xhr . responseText ) ;
16+ }
17+ } ;
18+ xhr . send ( null ) ;
19+ } ;
20+
21+ } else if ( typeof process !== "undefined" &&
22+ process . versions &&
23+ ! ! process . versions . node ) {
24+ //Using special require.nodeRequire, something added by r.js.
25+ fs = require . nodeRequire ( 'fs' ) ;
26+ fetchText = function ( path , callback ) {
27+ callback ( fs . readFileSync ( path , 'utf8' ) ) ;
28+ } ;
29+ }
1330
1431define ( [ 'babel' ] , function ( babel ) {
1532 return {
@@ -21,8 +38,20 @@ define(['babel'], function(babel) {
2138 code = babel . transform ( text , {
2239 sourceMap : 'inline'
2340 } ) . code ;
24- onload . fromText ( code ) ;
41+
42+ if ( config . isBuild ) {
43+ _buildMap [ name ] = code ;
44+ }
45+
46+ onload . fromText ( code ) ;
2547 } ) ;
48+ } ,
49+
50+ write : function ( pluginName , moduleName , write ) {
51+ if ( moduleName in _buildMap ) {
52+ // var text = jsEscape(buildMap[moduleName]);
53+ write . asModule ( pluginName + '!' + moduleName , _buildMap [ moduleName ] ) ;
54+ }
2655 }
2756 }
28- } ) ;
57+ } ) ;
0 commit comments