Skip to content

Commit deb8cb6

Browse files
author
Robert Mosolgo
authored
Merge pull request #560 from djudd/jsx-coffee-sprockets-4
Support .js.jsx.coffee files with Sprockets 4
2 parents cf206a2 + ed81296 commit deb8cb6

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ matrix:
4949

5050
allow_failures:
5151
- rvm: jruby-9.0.1.0
52-
- gemfile: gemfiles/rails_4.2_sprockets_4.gemfile
53-
- gemfile: gemfiles/rails_5_sprockets_4.gemfile
5452

5553
before_install:
5654
- mkdir travis-phantomjs

lib/react/rails/railtie.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ class Railtie < ::Rails::Railtie
104104
if Gem::Version.new(Sprockets::VERSION) >= Gem::Version.new("4.x")
105105
sprockets_env.register_mime_type("application/jsx", extensions: [".jsx", ".js.jsx", ".es.jsx", ".es6.jsx"])
106106
sprockets_env.register_transformer("application/jsx", "application/javascript", React::JSX::Processor)
107+
sprockets_env.register_mime_type("application/jsx+coffee", extensions: [".jsx.coffee", ".js.jsx.coffee"])
108+
sprockets_env.register_transformer("application/jsx+coffee", "application/jsx", Sprockets::CoffeeScriptProcessor)
107109
elsif Gem::Version.new(Sprockets::VERSION) >= Gem::Version.new("3.0.0")
108110
sprockets_env.register_engine(".jsx", React::JSX::Processor, mime_type: "application/javascript")
109111
else
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Sprockets 4 expects this file
2+
//
3+
//= link application.js
4+
//= link application.css

test/react_asset_test.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,15 @@ class ReactAssetTest < ActionDispatch::IntegrationTest
3636

3737
test "the development version with addons is loaded" do
3838
asset = Rails.application.assets.find_asset('react')
39-
assert asset.pathname.to_s.end_with?('development-with-addons/react.js')
39+
path =
40+
if asset.respond_to?(:pathname)
41+
# Sprockets < 4
42+
asset.pathname.to_s
43+
else
44+
# Sprockets 4+
45+
asset.filename
46+
end
47+
assert path.end_with?('development-with-addons/react.js')
4048
end
4149

4250
test "the production build is optimized for production" do

0 commit comments

Comments
 (0)