koa-webpack-hot-middleware provides a Koa-specific adapter for `webpack-hot-middleware`, enabling hot module replacement (HMR) for Webpack bundles within a Koa application. It allows developers to integrate HMR directly into an existing Koa server setup, complementing `webpack-dev-middleware` rather than relying on `webpack-dev-server`. The provided npm metadata shows a current version of 1.0.3, with the latest activity (according to search results for `koa-webpack-middleware` which seems to be the successor or a related project) around 2017. Given the project's age, its dependencies on older Webpack plugin APIs (like `webpack.optimize.OccurenceOrderPlugin()`, which is deprecated), and the lack of recent releases, the package appears to be effectively abandoned. Its primary utility is for legacy Koa projects still using older Webpack configurations, as modern Koa and Webpack setups typically use newer alternatives like `koa-webpack`.
npm install koa-webpack-hot-middlewareVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up `koa-webpack-hot-middleware` in a basic Koa application, integrating it with `webpack-dev-middleware` to provide hot module replacement for client-side assets. It includes a minimal Webpack configuration with the necessary plugins and client-side entry point for HMR, then shows how to apply both middlewares to a Koa server.
Remove `new webpack.optimize.OccurenceOrderPlugin()` from your Webpack plugins array. For modern Webpack versions, also replace `webpack.NoErrorsPlugin()` with `webpack.NoEmitOnErrorsPlugin()` or omit it as error handling has evolved.
For new projects or existing projects requiring active maintenance, consider using actively maintained alternatives such as `koa-webpack`, which bundles both development and hot module replacement middleware into a single module and supports modern Webpack and Koa versions.
Ensure your Webpack configuration's `entry` object includes `'webpack-hot-middleware/client'` for each entry point that requires HMR. For example: `entry: { app: ['webpack-hot-middleware/client?path=/__webpack_hmr&timeout=20000', './src/index.js'] }`.If using Koa 2.x or later, wrap `koa-webpack-hot-middleware` with `koa-convert` (e.g., `app.use(convert(koaWebpackHotMiddleware(compiler)))`) or migrate to a modern Koa webpack middleware that supports `async/await` natively, such as `koa-webpack`.
Ensure you are using a valid Koa application instance. For Koa 2.x and above, ensure your Koa app is initialized correctly (e.g., `const Koa = require('koa'); const app = new Koa();`). If using Koa 1.x, verify your Koa version and middleware application syntax.First, ensure `webpack-hot-middleware` is installed: `npm install --save-dev webpack-hot-middleware`. Then, verify that `'webpack-hot-middleware/client'` (often with query parameters like `?path=/__webpack_hmr&timeout=20000`) is included in the `entry` array or object of your webpack configuration for each bundle requiring HMR.
Remove `new webpack.optimize.OccurenceOrderPlugin()` from your webpack configuration's `plugins` array. For modern Webpack, it's not needed, and its absence won't affect functionality.