npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

parcel-plugin-prerender

v1.4.1

Published

prerender plugin for parcel

Downloads

84

Readme

parcel-plugin-prerender

About

Much like the prerender-spa-plugin for Webpack, this plugin is to bring prerendering capabilities to Parcel. It is meant to be a drop-in solution for any site or single-page-app.

Installation

npm install parcel-plugin-prerender -D

Usage

By default, this plugin will render the / path. As this plugin uses cosmiconfig, in order to add more paths, add an array of strings corresponding to the paths you want rendered in a routes key in your package.json, or a JSON or YAML .prerenderrc file, or export the key in a prerender.config.js file.

Example

{
  "prerender": {
    "routes": ["/", "/about", "/login", "/deep/nested/route"]
  }
}

Render configuration

You can configure the renderer (browser) options by using the following example config:

{
  "prerender": {
    "routes": ["/", "/about"],
    "rendererConfig": {
      "renderAfterDocumentEvent": "prerender-trigger"
    }
  }
}

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 / and /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:

document.dispatchEvent(new Event('prerender-trigger'));

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:

{
  "prerender": {
    "routes": ["/", "/about"],
    "rendererConfig": {
      "headless": false
    }
  }
}

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:

Recently, SSR (Server Side Rendering) has taken the JavaScript front-end world by storm. The fact that you can now render your sites and apps on the server before sending them to your clients is an absolutely revolutionary idea (and totally not what everyone was doing before JS client-side apps got popular in the first place...)

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.

Available Renderers

Currently only @prerenderer/renderer-puppeteer is supported, although @prerenderer/renderer-jsdom will probably be supported in the future