webpack-tool is a utility library designed to streamline webpack development and production builds, integrating a Koa-based development server with hot module replacement and a production build mechanism that can optionally display a build result UI. It ties its major version releases directly to webpack's major versions (e.g., `webpack-tool@5.x.x` for `webpack@5`). This approach provides a consistent experience for developers working with specific webpack versions. Key differentiators include its built-in Koa dev server, which offers `before` and `after` hooks for custom middleware integration, a proxy configuration, and a history API fallback. It aims to simplify the boilerplate often associated with setting up webpack for both development and production environments, providing a consolidated API for `server` (development) and `build` (production) commands, along with a debug UI for build results.
npm install webpack-toolVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to instantiate `WebpackTool`, configure its dev server with custom Koa middleware, proxying, and history API fallback, and then conditionally start either the development server or a production build based on an environment variable. It also shows a minimal webpack configuration.
Always install `webpack-tool` with a version that matches your installed `webpack` major version (e.g., `npm i webpack-tool@^5.0.0 webpack@^5.0.0`).
When using `devServer.before` or `devServer.after`, ensure your middleware functions are compatible with Koa's context and `async/await` pattern (`(ctx, next) => {...}`).Set `process.env.BUILD_VIEW = true` before calling `webpackTool.build(webpackConfig)` if you want to inspect the build result UI.
Review webpack configuration, especially loaders and plugins. Check for circular dependencies in modules. Try simplifying the configuration or isolating the problematic part. Increase Node.js stack size if necessary, e.g., `node --stack-size=4000 build/index.js`.
Ensure that the middleware provided to `before` or `after` is a valid Koa middleware function (taking `ctx` and `next` as arguments) and that the `app` object is indeed the Koa instance provided by `webpack-tool`.
Run `npm install webpack-tool --save` or `yarn add webpack-tool` in your project directory. Verify the package is listed in `package.json` and present in `node_modules`.