Skip to content
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

feat: prerender plugin #86

Merged
merged 40 commits into from
Jan 2, 2024
Merged

feat: prerender plugin #86

merged 40 commits into from
Jan 2, 2024

Conversation

rschristian
Copy link
Member

@rschristian rschristian commented Oct 16, 2023

Largely mimics WMR's setup, as that was pretty slick, with a few minor changes:

  • Can prerender into any template element, doesn't require document.body
  • Will search for prerender() function in any script listed in input HTML doc, doesn't require a certain placement
    • User can specify a prerender script through the plugin options instead, if they prefer/need to
  • Regex is fun, but switched off the HTML regex shenanigans for a real html parser. I'm a buzzkill, I know.

Patches for Vite's preloader were all that was needed to get the bundles working in Node. I've asked if they'd be willing to implement this upstream, but we'll see.

@rschristian rschristian force-pushed the feat/prerender-plugin branch 5 times, most recently from 8468c1a to 1d7648e Compare November 19, 2023 11:14
"preact": "^10.19.2",
"preact-iso": "^2.3.2",
"preact-render-to-string": "^6.3.1",
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"rollup": "^2.77.3",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done just for types -- newer versions of Vite (conveniently) expose Rollup's types (import type { Rollup } from 'vite') so we can drop this in the future.

src/prerender.ts Outdated Show resolved Hide resolved
src/prerender.ts Outdated Show resolved Hide resolved
@rschristian rschristian force-pushed the feat/prerender-plugin branch 2 times, most recently from 16b3136 to 9d709ab Compare November 20, 2023 11:41
src/prerender.ts Outdated Show resolved Hide resolved
@rschristian rschristian marked this pull request as ready for review December 13, 2023 09:44
src/prerender.ts Outdated Show resolved Hide resolved
@rschristian rschristian force-pushed the feat/prerender-plugin branch 2 times, most recently from 96dee28 to e930e5a Compare December 15, 2023 07:04
@rschristian rschristian force-pushed the feat/prerender-plugin branch 2 times, most recently from d3740ce to be9a099 Compare December 16, 2023 03:35
demo/src/index.tsx Outdated Show resolved Hide resolved
Copy link
Member

@JoviDeCroock JoviDeCroock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested in JoviDeCroock/blog-portfolio#60

Seems to work well, one of my "gripes" is that all the meta/... is rendered on a single line which might not be easy to read and validate for people.

We might want to write something up about this where wmr migration has become easier and so has SSG with our preset

demo/src/index.tsx Show resolved Hide resolved
demo/src/index.tsx Show resolved Hide resolved
package-lock.json Outdated Show resolved Hide resolved
src/prerender.ts Outdated Show resolved Hide resolved
@rschristian rschristian marked this pull request as draft December 29, 2023 08:05
@rschristian rschristian merged commit 8f87cda into main Jan 2, 2024
1 check passed
@rschristian rschristian deleted the feat/prerender-plugin branch January 2, 2024 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants