Copy this bookmark:



bookmark detail

webpack-hot-server-middleware: :fire: Hot reload webpack bundles on the server
Github repo
Name: webpack-hot-server-middleware
Tagline: :fire: Hot reload webpack bundles on the server
JavaScript = 16601 bytes

# Webpack Hot Server Middleware
[![Build Status](]( [![npm version](]( [![Coverage Status](]( [![npm downloads](](

Webpack Hot Server Middleware is designed to be used in conjunction with [`webpack-dev-middleware`]( (and optionally [`webpack-hot-middleware`]( to hot update Webpack bundles on the server.

## Why?

When creating universal Web apps it's common to build two bundles with Webpack, one client bundle [targeting]( 'web' and another server bundle targeting 'node'.

The entry point to the client bundle renders to the DOM, e.g.

// client.js

import ReactDOM from 'react-dom';
import App from './components/App';

ReactDOM.render(<App />, document.getElementById('root'));

And the entry point to the server bundle renders to string, e.g.

// server.js

import { renderToString } from 'react-dom/server';
import App from './components/App';

export default function serverRenderer() {
return (req, res, next) => {
<!doctype html>
<div id="root">
${renderToString(<App />)}
<script src="/client.js"></script>

> NOTE: The server bundle is itself middleware allowing you to mount it anywhere in an existing node server, e.g.

const express = require('express');
const serverRenderer = require('./dist/server');
const app = express();


Given this setup it's fairly easy to hook up hot module replacement for your client bundle using `webpack-dev-server` or `webpack-hot-middleware` however these middlewares don't handle server bundles meaning you need to frequently restart your server to see the latest changes.

Webpack Hot Server Middleware solves this problem, ensuring the server bundle used is always the latest compilation without requiring a restart. Additionally it allows your client and server bundle to share the same Webpack cache for faster builds and uses an in-memory bundle...
github  programming  github-starred-to-pinboard  crypto 
february 2018 by brianyang
view in context