sprockets-coffee-react 2.x is compatible with react ^0.12.0
sprockets-coffee-react 0.x is compatible with react <=0.11.0
Add this to your Gemfile:
gem 'sprockets-coffee-react'
Place a .js.coffee.cjsx
or .js.cjsx
file (or a .js.coffee
file with a @cjsx
pragma) in your assets directory. When you require it into other JS files the CJSX markup will be transformed and compiled to Javascript.
Eg. if you have a file called my-component.js.coffee
which contains some CJSX code, require it from application.js
or somewhere else:
//= require my-component
If you’re not using rails, you’ll need to register the Sprockets preprocessor manually. Here is an adapted version of the Rack example provided by Sprockets, which additionally requires and registers the sprockets-coffee-react engine:
require 'sprockets' require 'sprockets/coffee-react' map '/assets' do environment = Sprockets::Environment.new environment.append_path 'app/assets/javascripts' environment.append_path 'app/assets/stylesheets' environment.register_preprocessor 'application/javascript', Sprockets::CoffeeReact environment.register_engine '.cjsx', Sprockets::CoffeeReactScript environment.register_engine '.js.cjsx', Sprockets::CoffeeReactScript run environment end map '/' do run YourRackApp end
Released under the MIT License. See the LICENSE file for further details.