Skip to content

Sprockets preprocessor for CJSX (Coffeescript with React JSX markup)

License

Notifications You must be signed in to change notification settings

Johnius/sprockets-coffee-react

 
 

Repository files navigation

sprockets-coffee-react

Compatibility

sprockets-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 use

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

How to use with a Rack application

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

License

Released under the MIT License. See the LICENSE file for further details.

About

Sprockets preprocessor for CJSX (Coffeescript with React JSX markup)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 75.6%
  • HTML 9.0%
  • JavaScript 6.9%
  • CoffeeScript 3.4%
  • Shell 3.0%
  • CSS 2.1%