{"id":12928,"library":"build-statistics-webpack-plugin","title":"Webpack Build Statistics Plugin","description":"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.","status":"active","version":"1.0.3","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","webpack","build","statistics"],"install":[{"cmd":"npm install build-statistics-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add build-statistics-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add build-statistics-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This is a webpack plugin and requires webpack as a peer dependency.","package":"webpack","optional":false},{"reason":"Used internally for logging trace and error messages.","package":"debug","optional":false}],"imports":[{"note":"The package currently uses CommonJS module exports as shown in its documentation. ESM `import` might not work without specific Babel/TypeScript configuration or if the package doesn't provide an `exports` field for ESM.","wrong":"import BuildStatisticsPlugin from 'build-statistics-webpack-plugin';","symbol":"BuildStatisticsPlugin","correct":"const BuildStatisticsPlugin = require('build-statistics-webpack-plugin');"},{"note":"If using an ESM-aware environment (e.g., Node.js with 'type': 'module' or a bundler configured for ESM), the plugin is likely exposed as a default export. Named imports like `{ BuildStatisticsPlugin }` are incorrect.","wrong":"import { BuildStatisticsPlugin } from 'build-statistics-webpack-plugin';","symbol":"BuildStatisticsPlugin (ESM)","correct":"import BuildStatisticsPlugin from 'build-statistics-webpack-plugin';"}],"quickstart":{"code":"const path = require('path');\nconst BuildStatisticsPlugin = require('build-statistics-webpack-plugin');\n\nmodule.exports = {\n    mode: 'development',\n    entry: './src/index.js', // Ensure this entry point exists\n    output: {\n        filename: 'bundle.js',\n        path: path.resolve(__dirname, 'dist'),\n    },\n    plugins: [\n        new BuildStatisticsPlugin({\n            // The 'path' option must be an absolute, writable file path.\n            // It's recommended to use path.resolve() to ensure absoluteness.\n            path: path.resolve(__dirname, 'build-statistics.json'),\n        }),\n    ],\n};\n","lang":"javascript","description":"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."},"warnings":[{"fix":"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.","message":"The plugin does not write statistics files when changes are detected in webpack's watch mode or during incremental rebuilds. It only writes on initial full builds or complete recompilations, which can lead to incomplete data if continuous logging for every recompile is expected.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"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')`.","message":"The 'path' option, which specifies the absolute file path for the statistics output, is mandatory. Omitting it or providing an invalid/relative path can cause the plugin to fail during compilation or write to an unexpected location, potentially without clear error messages.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"For CommonJS, use `const BuildStatisticsPlugin = require('build-statistics-webpack-plugin');`. For ES Modules (if configured), use `import BuildStatisticsPlugin from 'build-statistics-webpack-plugin';`.","cause":"Attempting to import the plugin using an incorrect syntax, such as a named import when it's a default export, or mixing CommonJS `require` with ES module `import` patterns incorrectly.","error":"TypeError: BuildStatisticsPlugin is not a constructor"},{"fix":"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.","cause":"The specified 'path' option in the plugin configuration points to a directory that does not exist or is not writable by the build process, preventing the plugin from writing the statistics file.","error":"Error: ENOENT: no such file or directory, open '/nonexistent/path/build-stats.json'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}