-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simple server rendering #1100
Comments
this could be useful! I have already experimented with server rendering with create react app, but it's a little pain to setup. I end up wrapping each css imports with a helper function, and just included the generated css from the build script. (also need to be careful with browser globals). It would be handy if instead we have something like what @brigand said. |
I’d like to look at a proof of concept for this. PR? |
I would be interested in this too - my use case is performing SSR in Java using the Nashorn engine. However, since Nashorn doesn't have a module engine, I configure Webpack to export the bundle as a global. I export a render function from my entrypoint script, and call it from Nashorn. Here's an experiment for making this possible through CRA: Basically the user can opt-in to generating a library or module by adding config to their The diff shows a modified Thoughts? |
Config is a bit of a no-go for me but if you inferred them from |
I've updated the branch to generate a library name and use UMD: The result is usable through |
Send a PR? |
Will do, might be Monday though.
|
Would love to see this in the next CRA version 👍 |
Hi all, I can highly recommend Razzle along with my Razzle Material UI Styled Example for those who need Server Side Rendering right now and the easy way. |
https://github.com/antonybudianto/cra-universal No eject or code change needed! Also support code-splitting. |
These suggestions are interesting but they don't address the use-case of rendering outside of Node - in my case, using the Nashorn engine in Java. I can make it all work if I have a UMD build, which would be a very simple change. |
If you want CRA with SSR support, consider React App SDK, which uses CRA under the hood, just adds an ability to compile, run and test server-side code using regular CRA pipeline - |
There have been some people asking for server rendering with node.js, but what if instead we did server rendering agnostic of the backend?
The idea is to create a UMD build which exports one function. The function takes some arguments and returns a renderToString result. The generated version of this entry point would be very simple, but it could be extended by the user to support react-router, redux, etc. They can add these things without ejecting, which is nice.
This bundle could be used in node.js with a simple
require()
, or loaded into phpv8 or similar and expose a global.Building this bundle would be a separate build task with an optional watch mode. For node users, nodemon would pick up the bundle change and restart the server.
The text was updated successfully, but these errors were encountered: