Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions lib/react/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ class Railtie < ::Rails::Railtie
addons: app.config.react.addons,
})

sprockets_env = app.assets || app.config.assets # sprockets-rails 3.x attaches this at a different config
sprockets_env.version = [sprockets_env.version, "react-#{asset_variant.react_build}",].compact.join('-')
sprockets_env = app.assets || app.config.try(:assets) # sprockets-rails 3.x attaches this at a different config
if !sprockets_env.nil?
sprockets_env.version = [sprockets_env.version, "react-#{asset_variant.react_build}",].compact.join('-')
end

end

Expand All @@ -70,8 +72,10 @@ class Railtie < ::Rails::Railtie
addons: app.config.react.addons,
})

app.config.assets.paths << asset_variant.react_directory
app.config.assets.paths << asset_variant.jsx_directory
if app.config.respond_to?(:assets)
app.config.assets.paths << asset_variant.react_directory
app.config.assets.paths << asset_variant.jsx_directory
end
end

config.after_initialize do |app|
Expand All @@ -89,12 +93,14 @@ class Railtie < ::Rails::Railtie
end

initializer "react_rails.setup_engine", :group => :all do |app|
sprockets_env = app.assets || Sprockets # Sprockets 3.x expects this in a different place
if Gem::Version.new(Sprockets::VERSION) >= Gem::Version.new("3.0.0")
sprockets_env.register_mime_type("application/jsx", extensions: [".jsx", ".js.jsx", ".es.jsx", ".es6.jsx"])
sprockets_env.register_transformer("application/jsx", "application/javascript", React::JSX::Processor)
else
sprockets_env.register_engine(".jsx", React::JSX::Template)
sprockets_env = app.assets || defined?(Sprockets) && Sprockets # Sprockets 3.x expects this in a different place
if !sprockets_env.nil?
if Gem::Version.new(Sprockets::VERSION) >= Gem::Version.new("3.0.0")
sprockets_env.register_mime_type("application/jsx", extensions: [".jsx", ".js.jsx", ".es.jsx", ".es6.jsx"])
sprockets_env.register_transformer("application/jsx", "application/javascript", React::JSX::Processor)
else
sprockets_env.register_engine(".jsx", React::JSX::Template)
end
end
end
end
Expand Down