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

ssr-fatigue-react

v2.0.0-alpha.0

Published

Express middleware for server side rendering of React based apps

Downloads

6

Readme

ssr-fatigue-react

An Express middleware for server side rendering of React based web apps. It wraps:

When the ssr-fatigue-intl middleware is used, it will automatically add the messages, locale and, react-intl locale data to the output html.

For keeping things simple, the ssr-fatigue-config project contains some helper methods to build Webpack and Babel configurations in order to get things started without loosing too much sanity (no guarantees though).

Installation

$ npm i ssr-fatigue-react

Usage

src/server/index.js

import express from 'express'
import reactSSR from 'ssr-fatigue-react'

const app = express()

const assetDir = resolve(__dirname, 'path/to/webpack/output/dir')

app.use('/inc', express.static(assetDir))

app.get(
  '*',
  reactSSR({
    buildDir: assetDir,
    basePath: '', // (req, res) => res.get('X-Proxy-Base')
    publicPath: '/inc/web/', // path to assets (without basePath)
  })
)

src/client/entry-web.js

import { hot } from 'react-hot-loader/root'
import initClient from 'ssr-fatigue-react/client'

import App from '../shared/app'
import routeConfig from '../shared/routes'

// check out dynamic webpack public path
console.log('public path', __webpack_public_path__)

initClient(hot(App), routeConfig).then(() => console.log('App hydrated!'))

src/client/entry-node.js

export { default } from '../shared/app'
export routeConfig from '../shared/routes'

src/shared/routes.js

import React from 'react'
import loadable from '@loadable/component'

export default [
  {
    path: '/',
    exact: true,
    component: loadable(
      () => import(/* webpackPrefetch: true */ './pages/home'),
      {
        fallback: <div>Loading...</div>,
      }
    ),
  },
]

src/shared/app.js

import React from 'react'
import { Helmet } from 'react-helmet'

export default class App extends React.Component {
  static async getInitialProps({ getRouteProps, context }) {
    context.what = 'something to pass down to routes'

    return {
      routeProps: await getRouteProps(context),
    }
  }

  render() {
    return (
      <div className="container">
        <Helmet titleTemplate="My App - %s">
          <meta name="description" content="An example application" />
        </Helmet>
        {children}
      </div>
    )
  }
}

src/shared/pages/home.js

import React from 'react'
import { Helmet } from 'react-helmet'

export default class HomePage extends React.Component {
  static async getInitialProps(ctx) {
    const { req, what } = ctx

    return { what }
  }

  render() {
    return (
      <div className="row">
        <Helmet>
          <title>Home</title>
        </Helmet>
        <div className="col-xs-12">
          <h1>Home</h1>
          <p>{this.props.what}</p>
        </div>
      </div>
    )
  }
}

The given webpackConfig file should have two configurations for target web and node. Using the ssr-fatigue-config package:

webpack.config.js

const { resolve } = require('path')
const { buildWebpackConfig } = require('ssr-fatigue-config/webpack')

const entryDir = resolve(__dirname, 'src', 'client')
const buildDir = resolve(__dirname, 'build')

module.exports = [
  buildWebpackConfig({ target: 'node', buildDir, entryDir }),
  buildWebpackConfig({ target: 'web', buildDir, entryDir }),
]

babel.config.js

const { buildLocalBabelConfig } = require('ssr-fatigue-config/babel')

module.exports = buildLocalBabelConfig()