¶ ↑
sprockets-coffee-react¶ ↑
Compatibilitysprockets-coffee-react 2.x is compatible with react ^0.12.0
sprockets-coffee-react 0.x is compatible with react <=0.11.0
¶ ↑
How to useAdd this to your Gemfile:
gem 'sprockets-coffee-react'
Place a .js.coffee.cjsx
or .js.cjsx
file, or a .js.coffee
file 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
¶ ↑
How to use with a Rack applicationIf 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
¶ ↑
LicenseReleased under the MIT License. See the LICENSE file for further details.
¶ ↑
How to use with MiddlemanAdd the following to your config.rb file:
require 'sprockets/coffee-react' ::Sprockets.register_preprocessor 'application/javascript', ::Sprockets::CoffeeReact ::Sprockets.register_engine '.cjsx', ::Sprockets::CoffeeReactScript ::Sprockets.register_engine '.js.cjsx', ::Sprockets::CoffeeReactScript