@@ -59,8 +59,10 @@ class Railtie < ::Rails::Railtie
59
59
addons : app . config . react . addons ,
60
60
} )
61
61
62
- sprockets_env = app . assets || app . config . assets # sprockets-rails 3.x attaches this at a different config
63
- sprockets_env . version = [ sprockets_env . version , "react-#{ asset_variant . react_build } " , ] . compact . join ( '-' )
62
+ sprockets_env = app . assets || app . config . try ( :assets ) # sprockets-rails 3.x attaches this at a different config
63
+ if !sprockets_env . nil?
64
+ sprockets_env . version = [ sprockets_env . version , "react-#{ asset_variant . react_build } " , ] . compact . join ( '-' )
65
+ end
64
66
65
67
end
66
68
@@ -70,8 +72,10 @@ class Railtie < ::Rails::Railtie
70
72
addons : app . config . react . addons ,
71
73
} )
72
74
73
- app . config . assets . paths << asset_variant . react_directory
74
- app . config . assets . paths << asset_variant . jsx_directory
75
+ if app . config . respond_to? ( :assets )
76
+ app . config . assets . paths << asset_variant . react_directory
77
+ app . config . assets . paths << asset_variant . jsx_directory
78
+ end
75
79
end
76
80
77
81
config . after_initialize do |app |
@@ -93,14 +97,18 @@ class Railtie < ::Rails::Railtie
93
97
end
94
98
95
99
initializer "react_rails.setup_engine" , :group => :all do |app |
96
- sprockets_env = app . assets || Sprockets # Sprockets 3.x expects this in a different place
97
- if Gem ::Version . new ( Sprockets ::VERSION ) >= Gem ::Version . new ( "4.x" )
98
- sprockets_env . register_mime_type ( "application/jsx" , extensions : [ ".jsx" , ".js.jsx" , ".es.jsx" , ".es6.jsx" ] )
99
- sprockets_env . register_transformer ( "application/jsx" , "application/javascript" , React ::JSX ::Processor )
100
- elsif Gem ::Version . new ( Sprockets ::VERSION ) >= Gem ::Version . new ( "3.0.0" )
101
- sprockets_env . register_engine ( ".jsx" , React ::JSX ::Processor , mime_type : "application/javascript" )
102
- else
103
- sprockets_env . register_engine ( ".jsx" , React ::JSX ::Template )
100
+ # Sprockets 3.x expects this in a different place
101
+ sprockets_env = app . assets || defined? ( Sprockets ) && Sprockets
102
+
103
+ if !sprockets_env . nil?
104
+ if Gem ::Version . new ( Sprockets ::VERSION ) >= Gem ::Version . new ( "4.x" )
105
+ sprockets_env . register_mime_type ( "application/jsx" , extensions : [ ".jsx" , ".js.jsx" , ".es.jsx" , ".es6.jsx" ] )
106
+ sprockets_env . register_transformer ( "application/jsx" , "application/javascript" , React ::JSX ::Processor )
107
+ elsif Gem ::Version . new ( Sprockets ::VERSION ) >= Gem ::Version . new ( "3.0.0" )
108
+ sprockets_env . register_engine ( ".jsx" , React ::JSX ::Processor , mime_type : "application/javascript" )
109
+ else
110
+ sprockets_env . register_engine ( ".jsx" , React ::JSX ::Template )
111
+ end
104
112
end
105
113
end
106
114
end
0 commit comments