4
4
use Illuminate \Support \Facades \App ;
5
5
use Illuminate \Support \Facades \Blade ;
6
6
use Illuminate \Support \Facades \Config ;
7
+ use Illuminate \Support \Facades \Cache ;
7
8
8
9
class ReactServiceProvider extends ServiceProvider {
9
10
@@ -24,17 +25,33 @@ public function register() {
24
25
25
26
$ this ->app ->bind ('React ' , function () {
26
27
27
- $ defaultReactPath = implode (DIRECTORY_SEPARATOR ,
28
- [App::publicPath (), 'vendor ' , 'react-laravel ' , 'react.js ' ]);
28
+ if (App::environment ('production ' )
29
+ && Cache::has ('reactSource ' )
30
+ && Cache::has ('componentsSource ' )) {
29
31
30
- $ defaultComponentsPath = implode ( DIRECTORY_SEPARATOR ,
31
- [App:: publicPath (), ' js ' , ' components.js ' ] );
32
+ $ reactSource = Cache:: get ( ' reactSource ' );
33
+ $ componentsSource = Cache:: get ( ' componentsSource ' );
32
34
33
- $ reactPath = Config::get ('app.react.source ' , $ defaultReactPath );
34
- $ componentsPath = Config::get ('app.react.components ' , $ defaultComponentsPath );
35
+ }
36
+ else {
37
+ $ defaultReactPath = implode (DIRECTORY_SEPARATOR ,
38
+ [App::publicPath (), 'vendor ' , 'react-laravel ' , 'react.js ' ]);
35
39
36
- $ reactSource = file_get_contents ($ reactPath );
37
- $ componentsSource = file_get_contents ($ componentsPath );
40
+ $ defaultComponentsPath = implode (DIRECTORY_SEPARATOR ,
41
+ [App::publicPath (), 'js ' , 'components.js ' ]);
42
+
43
+ $ reactPath = Config::get ('app.react.source ' , $ defaultReactPath );
44
+ $ componentsPath = Config::get ('app.react.components ' , $ defaultComponentsPath );
45
+
46
+ $ reactSource = file_get_contents ($ reactPath );
47
+ $ componentsSource = file_get_contents ($ componentsPath );
48
+
49
+ if (App::environment ('production ' )) {
50
+ Cache::forever ('reactSource ' , $ reactSource );
51
+ Cache::forever ('componentsSource ' , $ componentsSource );
52
+ }
53
+
54
+ }
38
55
39
56
return new React ($ reactSource , $ componentsSource );
40
57
});
0 commit comments