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.
npm install webpack-hot-clientVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to integrate webpack-hot-client with an Express server and webpack-dev-middleware, ensuring proper port allocation and HMR setup.
Ensure your project uses Webpack 4. If upgrading to Webpack 5+, consider alternatives or check for community forks/updates supporting newer Webpack versions.
Modify your `webpack.config.js` to ensure the `entry` property adheres to the required array or object-of-arrays format, even for zero-config webpack v4+ setups.
Remove `new webpack.HotModuleReplacementPlugin()` from your `webpack.config.js` when `webpack-hot-client` is in use.
Implement the `client.server.on('listening', () => { /* start middleware/compilation here */ });` pattern as shown in the quickstart example to ensure port availability.Ensure your Node.js environment meets the specified engine requirements. Update Node.js to a supported LTS version if necessary.
Verify that your webpack `entry` option is an array or object-of-arrays. Ensure you are not manually including `HotModuleReplacementPlugin` if `autoConfigure` is enabled (which it is by default). Check the order of operations if using a dynamic port (see warnings).
Confirm the `webpack-hot-client` server is listening before webpack compilation starts (especially with `port: 0`). Ensure the `publicPath` in your webpack output configuration is correctly set. Check for other processes using the same port if a static port is configured.
Inspect the `compiler` and `options` passed to `hotClient` for validity. Ensure `webpack` and `webpack-hot-client` are correctly installed and imported. Verify your Node.js version is supported.