Server Rendering
It would be really awesome if I could render react components during the build process, similar to how it works in react-rails.
@josephwegner you can get server rendering quite easy
-
you'll have to add
react-rails -
extend the config.rb with something like this:
after_configuration do sprockets.append_path File.dirname(::React::Source.bundled_path_for('react.js')) ::React::Renderer.setup!( lambda {File.read(::React::Source.bundled_path_for('react-with-addons.js'))}, lambda { sprockets['components.js'].to_s }, {size: 10, timeout: 20}) end -
add a helper method
react_component(basically a copy of the one found in react-rails) butReactneeds to be prefixed with::so it doesn't grabs the wrong constant -
setup the components like in
react-rails -
add
//= require react_ujsto the application.js -
✓
I've created a pull request https://github.com/plasticine/middleman-react/pull/14 with support for this. I didn't pull in react-rails directly but pulled in a few components and changed it to work with middleman.