npm install parcel-plugin-prerender -D
By default, this plugin will render the
/ path when building with parcel (i.e.
parcel build or
process.env.NODE_ENV == "production").
As this plugin uses cosmiconfig,
in order to configure the plugin,
pass the configuration options in a
prerender key in your
or a JSON or YAML
.prerenderrc file, or export the config object in a
If you just want to render multiple routes, you can pass a plain array in any of the above ways:
Otherwise, you must pass it in a
routes key, in order to configure the renderer, as follows.
You can configure the renderer (browser) options by using the following example config:
This is particularly useful if you'd like to pre-fetch some API data or async config and make that part of your pre-rendered HTML.
In the example above, the
/about pages will only be rendered when the custom DOM event
prerender-trigger is dispatched.
You can do so in your code like the following:
The custom configuration can also be useful for debugging. If the resulting html does not look like what you're expecting you could use the following configuration:
To make the pre-render browser visible and you would be available to debug.
To see all the options available see this documentation
What is Prerendering?
To quote prerender-spa-plugin:
However, the same criticisms that were valid for PHP, ASP, JSP, (and such) sites are valid for server-side rendering today. It's slow, breaks fairly easily, and is difficult to implement properly.
Thing is, despite what everyone might be telling you, you probably don't need SSR. You can get almost all the advantages of it (without the disadvantages) by using prerendering. Prerendering is basically firing up a headless browser, loading your app's routes, and saving the results to a static HTML file. You can then serve it with whatever static-file-serving solution you were using previously. It just works with HTML5 navigation and the likes. No need to change your code or add server-side rendering workarounds.
In the interest of transparency, there are some use-cases where prerendering might not be a great idea.
- Tons of routes - If your site has hundreds or thousands of routes, prerendering will be really slow. Sure you only have to do it once per update, but it could take ages. Most people don't end up with thousands of static routes, but just in-case...
- Dynamic Content - If your render routes that have content that's specific to the user viewing it or other dynamic sources, you should make sure you have placeholder components that can display until the dynamic content loads on the client-side. Otherwise it might be a tad weird.
@prerenderer/renderer-puppeteer is supported, although
will probably be supported in the future