Making the helper for server side rendering work with JS created by Webpack
I want to enable the system of externally packaged js code (via Webpack) work with the server rendering library here: https://github.com/justin808/react-webpack-rails-tutorial
While I can and probably should make a separate project, I was wondering if it might make sense to submit a PR to this project. In a nutshell, the webpack system creates one JS file that the server side rendering would use.
So there's just a tiny part of this project that's relevant which is mostly the view helpers.
@chrisvfritz I seem to have formulated wrongly. I am not pissed of by "the developers" (in a way, I like to call myself developer, too, and please believe me that it's not my intent to offend anyone with that, nor you nor myself nor anyone at all, I just tend to formulate things wrongly more often). I am pissed of by the fact, that there aren't just more great different technologies than you could ever try out in your life, but there are even more different approaches again to implement these technologies (e.g. we got rails, we got react, and instead of one opinionated gem we got - as usual - two, or even more, (don't know, as I didn't look further)). As I said in my previous comment, the outburst of my personal feelings in this very thread is pure coincidence and I might indeed take this to a blog post.
However, I don't think the main statement I am trying to make is wrong here. The issue title says "Making the helper for server side rendering work with JS created by Webpack" and I am basically asking why it wasn't or isn't possible to extend / merge react-rails instead for the sake of better / bigger community and therefore provide more and better help resources ( @justin808 even suggested to do so earlier in this thread, but backed down, cause he was thinking the two gems vary too much. I think differently regarding this point as you might have noticed). Everything seems to hint that react-rails is going to take the same direction as react_on_rails and the outlook of the differences in fact seems minor to me. So: Why could this not become one bigger thing instead of two smaller in the future?
@thelamborghinistory Have you given react_on_rails more than a cursory glance? Respectfully, it sound like you're arguing from a position of what you think react_on_rails might be.
Your FOSS "utopia" taken to its end, would consist primarily of monolithic projects, with very little focus or discipline, paralyzed by legacy requirements. Concurrent development of concepts, especially when they're as distinct in intention as these two projects, is a good thing. This is also how the community explores concepts, tests best practices, etc.
I [need to] take this to a blog post.
@thelamborghinistory Have you given react_on_rails more than a cursory glance? Respectfully, it sound like you're arguing from a position of what you think react_on_rails might be.
@etcook believe it or not, but I am using it, not react-rails.
Did this issue ever get resolved? I.e. is there any way to add webpack assets to react-rails and have pre-rerendering work?
@catmando Have you tried https://github.com/shakacode/react_on_rails/ ?
@catmando Been playing with this all day. Got it working but I'm still unsure if its clean or not. Well, exposing components globally is pretty uggs but necessary here.
I ended up creating a separate "server_bundle.js" specific for this gem. That file gets picked up by a another server.js file with the react-server helper.
// server.js
//= require react-server
//= require server_bundle
# config/environments/development
config.react.server_renderer_options = {
files: ["server.js"],
}
I expose React and ReactDOM in my webpack config via the webpack-expose-loader. I use the same loader to expose all our components to window.
// Example file that'll get picked up by webpack.
// expose window.SampleApp from directory/file thats exporting the module.
require('expose?SampleApp!./sampleApp.js');
// Snippet of our webpack.base.config file.
module: {
loaders: [
{
test: require.resolve('react'),
loader: 'expose?React'
},
{
test: require.resolve('react-dom'),
loader: 'expose?ReactDOM'
}
],
...
},
You'll also need to import and expose the component in your client bundle as well. We have that being //= required in application.js as per norm.
The one thing I'm trying to figure out, and why I was crawling these issues, is how to get Rails to see the changes made to the server.js bundle without updating the view's controller or reloading the app.
Thanks for sharing some solutions here! I'll keep an eye out for forthcoming Rails 5.1 asset changes too, and see if there's anything react-rails can take advantage of.