webpack-hot-client

4.2.0 · active · verified Tue Apr 21

webpack-hot-client is a versatile client for integrating webpack Hot Module Replacement (HMR) into existing server frameworks like Express or Koa, without the need for webpack-dev-server. It enables real-time module updates in the browser during development. The current stable version is 4.2.0, with a release cadence that prioritizes stability, maintenance, and dependency updates, as seen in recent patch releases like 4.1.2. Its key differentiators include automatically setting up a WebSocket server for client-server communication, injecting necessary client-side scripts, and configuring webpack with the appropriate HMR plugins and entries at runtime. This allows developers to leverage HMR while retaining full control over their server infrastructure, making it ideal for projects that use custom server setups.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to integrate webpack-hot-client with an Express server and webpack-dev-middleware, ensuring proper port allocation and HMR setup.

const hotClient = require('webpack-hot-client');
const middleware = require('webpack-dev-middleware');
const webpack = require('webpack');
const express = require('express');
const app = express();

const config = require('./webpack.config'); // Ensure this points to your webpack config
const compiler = webpack(config);
const { publicPath } = config.output;
const options = { /* webpack-hot-client options, e.g., port: 8081 */ };

// We recommend calling the client _before_ adding the dev middleware
const client = hotClient(compiler, options);
const { server } = client;

server.on('listening', () => {
  console.log(`webpack-hot-client server listening on port ${server.address().port}`);
  app.use(middleware(compiler, { publicPath }));

  // Serve static files if needed, e.g., for an index.html
  // app.use(express.static('public'));

  app.listen(3000, () => {
    console.log('Express server listening on port 3000');
  });
});

view raw JSON →