diff --git a/lib/sprockets/coffee-react-script.rb b/lib/sprockets/coffee-react-script.rb index d2adc0b..091367d 100644 --- a/lib/sprockets/coffee-react-script.rb +++ b/lib/sprockets/coffee-react-script.rb @@ -23,5 +23,16 @@ def evaluate(scope, locals, &block) end end + def self.call(input) + filename = (input[:source_path] || input[:filename]).to_s + data = input[:data] + if filename =~ /\.coffee(\.source-.*)?\.cjsx/ + ::CoffeeReact.transform(data) + elsif filename =~ CJSX_EXTENSION + ::CoffeeScript.compile(::CoffeeReact.transform(data)) + else + data + end + end end end diff --git a/lib/sprockets/coffee-react.rb b/lib/sprockets/coffee-react.rb index 739f3a2..28daa60 100644 --- a/lib/sprockets/coffee-react.rb +++ b/lib/sprockets/coffee-react.rb @@ -21,10 +21,8 @@ def evaluate(scope, locals, &block) end def self.install(environment = ::Sprockets) - environment.register_preprocessor 'application/javascript', Sprockets::CoffeeReact - environment.register_postprocessor 'application/javascript', Sprockets::CoffeeReactPostprocessor - environment.register_engine '.cjsx', Sprockets::CoffeeReactScript - environment.register_engine '.js.cjsx', Sprockets::CoffeeReactScript + environment.register_mime_type 'application/x-cjsx',extensions: ['.cjsx', '.js.cjsx'] + environment.register_transformer 'application/x-cjsx', 'application/javascript', Sprockets::CoffeeReactScript end end end diff --git a/lib/sprockets/coffee-react/engine.rb b/lib/sprockets/coffee-react/engine.rb index 7cc954d..b1cef10 100644 --- a/lib/sprockets/coffee-react/engine.rb +++ b/lib/sprockets/coffee-react/engine.rb @@ -15,10 +15,8 @@ class Engine < ::Rails::Engine end def configure_env(env) - env.register_preprocessor 'application/javascript', Sprockets::CoffeeReact - env.register_postprocessor 'application/javascript', Sprockets::CoffeeReactPostprocessor - env.register_engine '.cjsx', Sprockets::CoffeeReactScript - env.register_engine '.js.cjsx', Sprockets::CoffeeReactScript + env.register_mime_type 'application/x-cjsx', extensions: ['.cjsx', '.js.cjsx'] + env.register_transformer 'application/x-cjsx', 'application/javascript', Sprockets::CoffeeReactScript end end end