Skip to content

Instantly share code, notes, and snippets.

@troelskn
Created November 1, 2017 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save troelskn/36936026ce88d021e63ef3ccf56dc294 to your computer and use it in GitHub Desktop.
Save troelskn/36936026ce88d021e63ef3ccf56dc294 to your computer and use it in GitHub Desktop.
Use sprockets-es6 to handle jsx
# config/initializers/sprockets.rb
module Sprockets
if respond_to?(:register_transformer)
register_mime_type 'text/jsx', extensions: ['.jsx'], charset: :unicode
register_transformer 'text/jsx', 'application/javascript', ::BabelTransformer
register_preprocessor 'text/jsx', DirectiveProcessor
end
if respond_to?(:register_engine)
args = ['.jsx', ::BabelTransformer]
args << { mime_type: 'text/jsx', silence_deprecation: true } if Sprockets::VERSION.start_with?("3")
register_engine(*args)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment