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

react-spa-prerender

v1.0.14

Published

React library for prerendering static pages, optimize SEO and web performance

Downloads

11,574

Readme

react-spa-prerender

The easiest way to prerender static pages, optimize SEO and build high performance for your React SPA. Build production-ready code just by adding few lines of code.

Upcoming features

  • Auto sitemap generation
  • Prebuilding pages with dynamic routes

Follow the steps below:

Install

With npm

npm install react-spa-prerender --save-dev

With yarn

yarn add react-spa-prerender --dev

Add as postbuild script

In your package.json add the following in the scripts section:

"scripts": {
    "postbuild": "react-spa-prerender",
}

Add .rsp.json file

.rsp.json is the configuration file for react-spa-prerender. Create this file in your application root folder. The minimum configuration requires the routes you want to be parsed. Example:

{
    routes: [
        "/",
        "/about",
        "/services"
        "/blog/article1"
        ...
    ]
}

From example above: Your "/" route will transform into "index.html" page. "/about" -> "about.html" "/services" -> "services.html" "/blog/article1" -> create blog directory with file "article1.html" ("/blog/article1.html") and so on...

The rest of the .rsp.json options described below

Add ReactDOM.hydrate in your index.js

In your index.js(main app file) change the ReactDOM.render logic:

import ReactDOM from 'react-dom';

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

Into following:

import ReactDOM from 'react-dom';

const rootElement = document.getElementById("root");

if (rootElement.hasChildNodes()) {
  ReactDOM.hydrate(<App />, rootElement);
} else {
  ReactDOM.render(<App />, rootElement);
}

Voila!!!

That's it. After accomplishing all the steps above, run you build command and your prerendered files will be in your build directory.

.rsp.json Options

|option | type | default | description | |-----|--------|------|---------| | routes(Required) | Array | - | An array of routes you want to parse and prerender into static html| | port | Number | 3000 | port where prerendering server will be starting | | buildDirectory | String | './build' | a relative path to your build folder |engine | Object | {} | params for Puppeteer engine, list of available params described below

Engine options:

Example of .rsp.json with engine options:

{
  "port": 3000,
  "buildDirectory": "./build",
  "engine": {
    "launchOptions": {
      "args": ["--no-sandbox", "--disable-setuid-sandbox"],
      "product": "chrome",
      "headless": true,
      "ignoreHTTPSErrors": true
    },
    "gotoOptions": {
      "timeout": 0
    }
  },
  "routes": [
    "/",
    "/about",
    "/services",
    "/blog/article1",
    "/blog/article2"
  ]
}