The `build-statistics-webpack-plugin` is a webpack plugin designed to capture and report detailed timing information for various stages of the webpack build process. It records data such as the build hash and the `startTime`, `endTime`, and `elapse` for distinct phases like `start`, `load`, `assets`, `uglify`, and `emit`. This data is then written to a specified JSON file. Primarily intended for performance monitoring, it supports regular `webpack build`, `webpack watch`, and `webpack-dev-server` scenarios. However, it explicitly notes that it does not write new statistics files during incremental rebuilds in watch mode. The current stable version is 1.0.3, suggesting it is an early-stage project. It differentiates itself by offering a straightforward, file-based output for build metrics, which is highly beneficial for CI/CD pipelines or local optimization efforts. Debugging output can be enabled via the `debug` package by setting the `DEBUG` environment variable.
npm install build-statistics-webpack-pluginVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to integrate `BuildStatisticsPlugin` into a `webpack.config.js` file to capture build performance metrics and save them to a specified JSON file.
Be aware of this limitation when analyzing build performance in development workflows. For full rebuilds, stop and restart the watch process or trigger a fresh build.
Always provide an absolute, writable path in the plugin configuration, using Node.js's `path.resolve()` for robustness, e.g., `path: path.resolve(__dirname, 'build-stats.json')`.
For CommonJS, use `const BuildStatisticsPlugin = require('build-statistics-webpack-plugin');`. For ES Modules (if configured), use `import BuildStatisticsPlugin from 'build-statistics-webpack-plugin';`.Ensure the directory for the output file exists and is writable before webpack runs. You might need to programmatically create the directory using Node.js's `fs.mkdirSync(path.dirname(filePath), { recursive: true })` within your `webpack.config.js` if it's dynamic.