Registry / devops / webpack-stats-plugin

webpack-stats-plugin

JSON →
library1.1.3jsnpmunverified

A webpack plugin that ingests the compiler's stats object, transforms it, and writes a JSON file (typically 'stats.json') to the output directory. Version 1.1.3 is the current stable release, updated primarily with patch-level maintenance. Key differentiator: it is a dedicated, minimal stats-file writer without the overhead of full-featured analysis tools. It supports custom transforms (sync or Promise), selective field filtering, and works with webpack 4 and 5. Maintained by Formidable Labs.

npm install webpack-stats-plugin
INSTALL
IMPORT
SIG · WEBPACK-STATS-PLUG
W
webpack-stats-plugin
devopsjavascriptv1.1.3
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

StatsWriterPlugin
✓ const { StatsWriterPlugin } = require('webpack-stats-plugin');
✗ const StatsWriterPlugin = require('webpack-stats-plugin');
Named export via CommonJS. ESM support not provided; using a default import will fail.
StatsWriterPlugin (ESM)
✓ import { StatsWriterPlugin } from 'webpack-stats-plugin';
✗ import StatsWriterPlugin from 'webpack-stats-plugin';
Named export. Default import yields undefined.
None
✓ const { StatsWriterPlugin } = require('webpack-stats-plugin');
✗ const statsPlugin = require('webpack-stats-plugin');
The package only exports StatsWriterPlugin; accessing it via a default require gives an object with the named export.

Basic webpack config that writes the full stats object to a file named 'stats.json' with formatting.

const { StatsWriterPlugin } = require('webpack-stats-plugin'); module.exports = { // ... other config plugins: [ new StatsWriterPlugin({ filename: 'stats.json', fields: null, // include all fields transform(data) { return JSON.stringify(data, null, 2); }, }), ], };
Debug
Known issues
gotchaThe `fields` option defaults to `["assetsByChunkName"]`, so by default not all stats properties are written.
fix
Set `fields: null` to include all stats fields, or provide an array of field names you need.
affects: *
gotchaThe `filename` can be a function returning a string, but the function receives the compilation data and must be synchronous.
fix
If using a function for `filename`, ensure it returns a string synchronously. For async filename generation, use the `transform` option.
affects: *
gotchaThe plugin does not automatically emit the stats file in development mode or when `emit: false`. By default `emit: true`.
fix
If you don't see the stats file, ensure you have `emit: true` (the default) or check that the webpack output path is correct.
affects: *
gotchaWhen using webpack 5 with `output.clean: true`, the stats file may be deleted on rebuild if not emitted correctly.
fix
Ensure `emit` is `true` (default) and that `filename` is within the output path. The plugin adds the file to the compiler's assets.
affects: >=1.1.0
Errors
Common errors & fixes
Error: Cannot find module 'webpack-stats-plugin'
Package not installed or installed only as a dev dependency but not required correctly.
fix
Run `npm install --save-dev webpack-stats-plugin` and ensure it's in node_modules.
TypeError: webpack_stats_plugin_1.StatsWriterPlugin is not a constructor
Wrong import syntax, likely using default import with CommonJS or incorrect require.
fix
Use `const { StatsWriterPlugin } = require('webpack-stats-plugin');` (named export) or `import { StatsWriterPlugin } from 'webpack-stats-plugin';` in ESM.
Stats file is empty or missing expected fields
The `fields` option restricts included fields; defaults to `["assetsByChunkName"]`.
fix
Set `fields: null` to include all stats fields, or explicitly include needed fields like `['assets', 'chunks', 'modules']`.
TypeError: data.toJson is not a function
The transform function receives the raw stats object directly (not a compiler stats instance) in recent versions.
fix
Access `data` directly as the transformed JSON object; do not call `.toJson()` on it. For custom stats generation, use the `stats` option described above.
Upgrade
Version history
1.1.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
16
Resources
webpack-stats-plugin — npm install webpack-stats-plugin · libregistry