Dashboard Build: Use StaticSiteGeneratorPlugin to build Static HTML#12381
Dashboard Build: Use StaticSiteGeneratorPlugin to build Static HTML#12381
Conversation
|
Caution: This PR has changes that must be merged to WordPress.com |
|
Thank you for the great PR description! When this PR is ready for review, please apply the Scheduled Jetpack release: June 4, 2019. |
|
Thanks @jeherve and @zinigor for reviewing! ❤️
Answered here:
|
This commit adds infrastructure to server-side render individual React components during build so they can be used in PHP. The idea is that props can be passed to the component using a simplistic templating language on the server side. The benefit is that we'll be able to re-use markup and styling and don't have to duplicate code in PHP. This is inspired by [prior art in `static.jsx`](https://github.com/Automattic/jetpack/blob/f25e25705c67146317c1cb7334856352bd47b44b/webpack.config.js#L43-L76) -- see e.g.#12381 -- but hopes to apply the same principle in a cleaner, more granular way (component level). It also adds functionality to fetch plans data from the relevant WP.com endpoint.
Closes #12127 (this is a simpler version of that PR). Prep work for #12072.
Big props @sirreal who pointed me to the right Webpack plugin for the job 👍
Changes proposed in this Pull Request:
tools/builder/react.jsusesstatic.jsxto produce minimal static markup (HTML) versions of the dashboard (really just "Turn on your JavaScript" notices). Itrequire()s the webpack-bundled version ofstatic.jsxto that end, and attachesrenderToStaticMarkup()-produced strings towindow, which it then writes to HTML files.Getting rid of the complexity added by passing information by attaching to
window(and thus requiringjsdometc) is the main objective of this PR. This is achieved by usingStaticSiteGeneratorPlugin, which is meant for this kind of thing. In a subsequent PR, I hope to get rid oftools/builder/react.jspretty much entirely. This will make it much easier to base the build system for Jetpack's React Dashboard oncalypso-build(see #12072).Testing instructions:
wp-admin/admin.php?page=jetpack#/settings)/wp-admin/admin.php?page=jetpack_modulesProposed changelog entry for your changes:
Dashboard Build: Use StaticSiteGeneratorPlugin to build Static HTML