-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Build website based on the published code #706
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
Conversation
|
Build successful! 🎉 |
| import docs from 'docs:@react-aria/overlays'; | ||
| import {HeaderInfo, PropTable} from '@react-spectrum/docs'; | ||
| import packageData from '../package.json'; | ||
| import packageData from '@react-aria/overlays/package.json'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to make sure we always load the package.json this way from now on. When building for production, the code and docs aren't in the same file structure so relative paths won't work.
| resolutions: packageJSON.resolutions, | ||
| browserslist: packageJSON.browserslist, | ||
| scripts: { | ||
| build: "PARCEL_WORKER_BACKEND=process parcel build 'docs/*/*/docs/*.mdx' 'packages/dev/docs/pages/**/*.mdx' --no-scope-hoist", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @mischnic had to turn off scope hoisting here. The ListBox page throws an error: Uncaught ReferenceError: $a5f3adf7483dfc2b62c1ecfb0311eae$export$Section is not defined. I didn't have a chance to look into it yet.
|
Build successful! 🎉 |
|
Build successful! 🎉 |
This PR has two parts: the new parcel build strategy, and building the website based on published code when deploying to the public site.
New Parcel build strategy
TL;DR it outputs smaller JS and CSS with less duplication. e.g. the Breadcrumbs page loaded 3 CSS files amounting to ~40kB before, and now loads a single CSS file that's only 30kB. 🎉
Previously, we used a custom parcel packager plugin to do the static rendering of react components during the build. This required the MDX transformer to do some hacks using inline bundles to create a fake HTML file with some inline JS that was later transformed into the final HTML by the packager. Now it's possible to change the type of file in an Optimizer plugin, so this allows the JS to go through the pipeline as normal, and get rendered to HTML as a final step. This is much simpler and less hacky.
In addition, we now keep all JS and CSS referenced from the MDX file (both in the server and client bundles) in the same bundle group, which allows Parcel to deduplicate them. And Parcel also now optimizes for HTTP/2, so more code can be deduplicated into smaller bundles between pages, leading to better caching. Finally, we ensure that all CSS is minified properly. Some of it wasn't before because it came from the server JS bundle, which is unminified (since it'll be running ahead of time).
Building the website based on published code
The second part is a script that builds the website based on the published code from npm rather than the current code in the repo when deploying the public website (not on PRs). This required copying the necessary code to actually build the docs, along with the current MDX files from the repo into a temporary directory. Then, we install the current code from npm and generate the docs as normal. Finally, we copy the result back into the repo and deploy it.