-
Notifications
You must be signed in to change notification settings - Fork 754
Switch to the new Sprockets processor #385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module React | ||
module JSX | ||
class Processor | ||
def self.instance | ||
@instance ||= new | ||
end | ||
|
||
def self.call(input) | ||
instance.call(input) | ||
end | ||
|
||
def call(input) | ||
{data: JSX::transform(input[:data])} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. from https://github.com/rails/sprockets#return-hash:
Can we return a string only? Do we need any metadata? |
||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,12 @@ module Rails | |
class Engine < ::Rails::Engine | ||
initializer "react_rails.setup_engine", :group => :all do |app| | ||
sprockets_env = app.assets || Sprockets # Sprockets 3.x expects this in a different place | ||
sprockets_env.register_engine(".jsx", React::JSX::Template) | ||
if Gem::Version.new(Sprockets::VERSION) >= Gem::Version.new("3.0.0") | ||
sprockets_env.register_mime_type("application/jsx", extensions: [".jsx", ".js.jsx"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this for handling requests with mime-type For react-rails, I think all requests are There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is only the internal Sprockets mime-type definition. That's the way Sprockets maps extensions with transformers - via mime-types. register_mime_type arbitrary_mime_type, extensions: list_of_extensions
register_transformer arbitrary_mime_type, target_mime_type, SomeProcessor https://github.com/rails/sprockets/blob/master/lib/sprockets.rb Starting version 4 you will no longer be able to map extensions directly to transformers so the mime-type is actually required. We cannot use the existing Their 2->3 upgrade doc even says: Alternatives to
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the explanation! I see why you chose to do it this way and it sounds good to me! |
||
sprockets_env.register_transformer("application/jsx", "application/javascript", React::JSX::Processor) | ||
else | ||
sprockets_env.register_engine(".jsx", React::JSX::Template) | ||
end | ||
end | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we benefit from having
@instance
? What if this class method was simplywould that be sufficient?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, there's no benefit if there's no caching.