middleman-react icon indicating copy to clipboard operation
middleman-react copied to clipboard

Server Rendering

Open josephwegner opened this issue 11 years ago • 2 comments

It would be really awesome if I could render react components during the build process, similar to how it works in react-rails.

josephwegner avatar Jul 17 '14 19:07 josephwegner

@josephwegner you can get server rendering quite easy

  1. you'll have to add react-rails

  2. 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
    
  3. add a helper method react_component (basically a copy of the one found in react-rails) but React needs to be prefixed with :: so it doesn't grabs the wrong constant

  4. setup the components like in react-rails

  5. add //= require react_ujs to the application.js

kangguru avatar Apr 22 '15 19:04 kangguru

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.

wschenk avatar Apr 26 '15 00:04 wschenk