Skip to content

Sprockets preprocessor for CJSX (Coffeescript with React JSX markup)

License

Notifications You must be signed in to change notification settings

gradescope/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 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.

How to use with Middleman

Add 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

About

Sprockets preprocessor for CJSX (Coffeescript with React JSX markup)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 77.8%
  • HTML 8.7%
  • JavaScript 5.1%
  • CoffeeScript 3.2%
  • Shell 3.1%
  • CSS 2.1%