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

stateful-react-container-webpack-plugin

v0.4.0

Published

A simple plugin that adds a React container element with initial state from the server to a template built with HtmlWebpackPlugin

Downloads

37

Readme

stateful-react-container-webpack-plugin

This Webpack plugin in intended to be used with html-webpack-plugin in projects using React.js. This plugin allows you to use html-webpack-plugin to build templates automatically with Webpack while also server-side rendering and passing initial state to the React.js client-side app.

There may be an example of the usage over at Kit when I've had time to update it. See the Example output to get an idea what this does.

Installation

npm install -S stateful-react-container-webpack-plugin

Setup

After installing the plugin, you will need to add it to the plugins in your Webpack configuration:

plugins: [
  new HtmlWebpackPlugin(),
  new StatefulReactContainerPlugin(),
],

Options

The plugin provides three options (passed as an object argument to the plugin) to customize usage:

  • id (default: container): The id of the React container.js element.
  • attribute (default: state): The name of the data attribute to store the initial state for the React.js app.
  • variable (default: state): The name of the variable containing the initial state in the template.
  • noState (default: false): Omits the data attribute and its value. This is useful if you only want this plugin to generate the container element and are not using server rendering.
  • position (default: 'start'): Determines whether the container is immediately after the opening body tag or immediately before the closing tag. Can be either 'start' or 'end'.

Example output

With the default configuration, the <body> tag is replaced with the following markup:

<body><div id="container" data-state="<%= state %>"></div>

Notes

This plugin assumes that you're using ejs to render your templates on the server side (hence the <%= state %> in the output). Using Express.js, you might render the built template as follows:

// in a request handler
const state = JSON.stringify({
  user: req.session.user,
});
res.render('app.ejs', { state });