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-static-site-hydrater

v5.0.1

Published

A Node.js library to hydrate static React sites

Downloads

5

Readme

react-static-site-hydrater

🚧 This plugin is currently a work in progress 🚧

Build Status

Due to this being a work in progress, it is necessary to either write your application in ES5 without import/export, or to use Babel to transform your code prior to Webpack being called. This is because it is currently necessary to import parts of the app into the Webpack build.

A Webpack plugin to create html static file sites from React apps using ReactDOM.hydrate, which can be hosted statically. They can also make use of Apollo for GraphQL and Helmet for SEO/social.

Usage

Installation

npm install --save-dev react-static-site-hydrater

Webpack configuration

The plugin will generate HTML5 files for the routes you specify. Just add the plugin to your webpack configuration as follows, along with the routes you want to generate. It works in conjunction with html-webpack-plugin:

const HtmlWebpackPlugin = require('html-webpack-plugin');
const ReactStaticSiteHydrater = require('react-static-site-hydrater').default;

const App = require('./src/app');

module.exports = {
  plugins: [
    new HtmlWebpackPlugin(),
    new ReactStaticSiteHydrater({
      routes: ['/', '/about', '/contact-us'],
      componentPath: App,
    }),
  ],
};

NB. See the examples folder for working sample applications.

This will generate the static site within the output folder (here dist):

˫dist
  ˫__index.html
  ˫__about.html
  ˫__contact-us.html

It will also produce a new or update an existing Firebase hosting config (./firebase.json) with rewrites to the static site for the routes specified above:

{
  "hosting": {
    "public": "dist",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
    // Add the "rewrites" attribute within "hosting"
    "rewrites": [
      {
        // Serves index.html for requests to files or directories that do not exist
        "source": "**",
        "destination": "/__index.html"
      },
      {
        // Serves __about.html for requests to /about
        "source": "/about",
        "destination": "/__about.html"
      },
      {
        // Serves __contact-us.html for requests to /contact-us
        "source": "/contact-us",
        "destination": "/__contact-us.html"
      },
      {
        // Excludes specified pathways from rewrites
        "source": "!/@(js|css)/**",
        "destination": "/__index.html"
      }
    ]
  }
}

Options

| Name | Type | Default | Description | | :-----------------: | :-----------------------------------: | :-----: | :---------------------------------------------------------------------------------------------------------------------------------- | | routes | {Array<String>} | [] | The routes to build (e.g. ['/', '/about', '/contact-us']) | | componentPath | {String} | | The full path to the application's main component with the routing/Switch, but not the Router | | plugins | {Array<String or PluginDescriptor>} | | List of plugins to use to create the static content (e.g. ['react-router', 'helmet', ['apollo', { client: new ApolloClient() }]]) |

Remaining features to be implemented

This Webpack plugin is not yet feature complete. It requires the following to be implemented:

  • Generation of the ./firebase.json file

Developing

Clone the repo and install dependencies

git clone [email protected]:jondarrer/react-static-site-hydrater
cd react-static-site-hydrater
npm install

Test

Tests are run using Jest.

npm test

Publish

Travis CI is the integration tool used to publish the package. It will publish new versions to npm, which can be created and tagged in Git using the npm version tool:

npm version {patch/minor/major} -m ":bookmark: Update release version to %s"
git push
git push --tags