Static generation requires two bundles to be generated from the React source. The first is the server bundle, which is bundled to target node. This bundle is required by the build script that calls the react-dom/server
package's renderToString
function.
The renderToString
function should be called once per page and should be passed the root React component for that page.
The second bundle is the client bundle which targets the browser.
- Find all of the root page components.
- Generate an entry point file for these that wraps the component with necessary data
- Each of these will serve an our entry point for both our client & server bundles.
- Produce a client bundle from the page component
- Output an HTML file for each page that uses
renderToString
function to statically generate markup.
Shared components should be moved into a common bundle that can be loaded on all pages