Koa Webpack is a development and hot module reloading middleware for Koa2 applications. It wraps and composes `webpack-dev-middleware` and `webpack-hot-client` into a single, cohesive middleware module, simplifying the integration of Webpack into a Koa server. Version 6.0.0 is the current stable release, which dropped support for Node.js 8. The package generally follows a maintenance release cadence with occasional minor updates, and major versions are released when significant breaking changes occur in its underlying dependencies (like `webpack-hot-client`) or Node.js compatibility is updated. A key differentiator is its ability to automatically use the `webpack` module and `webpack.config.js` from the project root, reducing boilerplate compared to other Koa Webpack integration solutions.
npm install koa-webpackVerified import paths — ran on the pinned version, not inferred.
This example sets up a basic Koa server integrated with `koa-webpack`, demonstrating how to use a custom Webpack compiler and configure options for both `webpack-dev-middleware` and `webpack-hot-client`. It listens on port 3000.
Upgrade your Node.js environment to version 10.0.0 or higher.
Rename the `dev` option to `devMiddleware` and the `hot` option to `hotClient` when configuring the middleware.
Ensure you `await` the result of `koaWebpack(options)` or handle the returned Promise with `.then()` before passing it to `app.use()`.
Install `webpack` version `^4.28.0` or higher in your project's dependencies using `npm install webpack` or `yarn add webpack`.
Upgrade to `koa-webpack@5.2.3` or a newer version to include these security fixes.
Modify your code to `const middleware = await koaWebpack(options); app.use(middleware);` ensuring you await the Promise.
Install webpack using your package manager: `npm install webpack` or `yarn add webpack`.
Update your configuration to use `devMiddleware` instead of `dev` and `hotClient` instead of `hot`.