{"id":13801936,"url":"https://github.com/FormidableLabs/webpack-stats-plugin","last_synced_at":"2025-05-13T12:32:04.243Z","repository":{"id":634707,"uuid":"30505391","full_name":"FormidableLabs/webpack-stats-plugin","owner":"FormidableLabs","description":"Webpack stats plugin for build information, file manifests, etc.","archived":false,"fork":false,"pushed_at":"2025-01-10T16:55:50.000Z","size":2213,"stargazers_count":355,"open_issues_count":10,"forks_count":33,"subscribers_count":32,"default_branch":"main","last_synced_at":"2025-04-06T07:38:00.574Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FormidableLabs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-02-08T20:54:04.000Z","updated_at":"2025-02-17T22:01:39.000Z","dependencies_parsed_at":"2023-02-17T21:01:11.964Z","dependency_job_id":"f26de459-3463-4d76-8657-45c3a5256abf","html_url":"https://github.com/FormidableLabs/webpack-stats-plugin","commit_stats":{"total_commits":104,"total_committers":16,"mean_commits":6.5,"dds":0.6634615384615384,"last_synced_commit":"1856acd86aff19e3415d59e46e4ab1e75a604245"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FormidableLabs%2Fwebpack-stats-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FormidableLabs%2Fwebpack-stats-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FormidableLabs%2Fwebpack-stats-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FormidableLabs%2Fwebpack-stats-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FormidableLabs","download_url":"https://codeload.github.com/FormidableLabs/webpack-stats-plugin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253942498,"owners_count":21988067,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T00:01:30.849Z","updated_at":"2025-05-13T12:32:04.220Z","avatar_url":"https://github.com/FormidableLabs.png","language":"JavaScript","readme":"\u003ca href=\"https://commerce.nearform.com/open-source/\" target=\"_blank\"\u003e\n  \u003cimg alt=\"Webpack Stats Plugin\" src=\"https://oss.nearform.com/api/banner.svg?badge=Webpack%20Stats%20Plugin\u0026bg=e8b25a\" /\u003e\n\u003c/a\u003e\n\n\u003cbr /\u003e\n\u003cbr /\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://npmjs.com/package/webpack-stats-plugin\"\u003e\n    \u003cimg alt=\"weekly downloads\" src=\"https://img.shields.io/npm/dw/webpack-stats-plugin\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://npmjs.com/package/webpack-stats-plugin\"\u003e\n    \u003cimg alt=\"current version\" src=\"https://img.shields.io/npm/v/webpack-stats-plugin\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/FormidableLabs/webpack-stats-plugin/actions\"\u003e\n    \u003cimg alt=\"build status\" src=\"https://github.com/FormidableLabs/webpack-stats-plugin/actions/workflows/ci.yml/badge.svg\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/FormidableLabs/webpack-stats-plugin#maintenance-status\"\u003e\n    \u003cimg alt=\"Maintenance Status\" src=\"https://img.shields.io/badge/maintenance-active-green.svg?color=brightgreen\u0026style=flat\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/FormidableLabs/webpack-stats-plugin/blob/main/LICENSE.txt\"\u003e\n  \u003cimg alt=\"license\" src=\"https://img.shields.io/npm/l/webpack-stats-plugin?color=brightgreen\u0026style=flat\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\nThis plugin will ingest the webpack [stats](https://webpack.js.org/configuration/stats/#stats) object, process / transform the object and write out to a file for further consumption.\n\nThe most common use case is building a hashed bundle and wanting to programmatically refer to the correct bundle path in your Node.js server.\n\n## Installation\n\nThe plugin is available via [npm](https://www.npmjs.com/package/webpack-stats-plugin):\n\n```sh\n$ npm install --save-dev webpack-stats-plugin\n$ yarn add --dev webpack-stats-plugin\n```\n\n## Examples\n\nWe have example webpack configurations for all versions of webpack. See., e.g. [`test/scenarios/webpack5/webpack.config.js`](test/scenarios/webpack5/webpack.config.js).\n\n### CLI\n\nIf you are using `webpack-cli`, you can enable with:\n\n```sh\n$ webpack-cli --plugin webpack-stats-plugin/lib/stats-writer-plugin\n```\n\n### Basic\n\nA basic `webpack.config.js`-based integration:\n\n```js\nconst { StatsWriterPlugin } = require(\"webpack-stats-plugin\");\n\nmodule.exports = {\n  plugins: [\n    // Everything else **first**.\n\n    // Write out stats file to build directory.\n    new StatsWriterPlugin({\n      filename: \"stats.json\", // Default\n    }),\n  ],\n};\n```\n\n### Custom `stats` Configuration\n\nThis option is passed to the webpack compiler's [`getStats().toJson()`](https://webpack.js.org/api/node/#statstojsonoptions) method.\n\n```js\nconst { StatsWriterPlugin } = require(\"webpack-stats-plugin\");\n\nmodule.exports = {\n  plugins: [\n    new StatsWriterPlugin({\n      stats: {\n        all: false,\n        assets: true,\n      },\n    }),\n  ],\n};\n```\n\n### Custom Transform Function\n\nThe transform function has a signature of:\n\n```js\n/**\n * Transform skeleton.\n *\n * @param {Object} data           Stats object\n * @param {Object} opts           Options\n * @param {Object} opts.compiler  Current compiler instance\n * @returns {String}              String to emit to file\n */\nfunction (data, opts) {}\n```\n\nwhich you can use like:\n\n```js\nconst { StatsWriterPlugin } = require(\"webpack-stats-plugin\");\n\nmodule.exports = {\n  plugins: [\n    new StatsWriterPlugin({\n      transform(data, opts) {\n        return JSON.stringify(\n          {\n            main: data.assetsByChunkName.main[0],\n            css: data.assetsByChunkName.main[1],\n          },\n          null,\n          2\n        );\n      },\n    }),\n  ],\n};\n```\n\n### Promise transform\n\nYou can use an asynchronous promise to transform as well:\n\n```js\nconst { StatsWriterPlugin } = require(\"webpack-stats-plugin\");\n\nmodule.exports = {\n  plugins: [\n    new StatsWriterPlugin({\n      filename: \"stats-transform-promise.json\",\n      transform(data) {\n        return Promise.resolve().then(() =\u003e\n          JSON.stringify(\n            {\n              main: data.assetsByChunkName.main,\n            },\n            null,\n            INDENT\n          )\n        );\n      },\n    }),\n  ],\n};\n```\n\n## Plugins\n\n- [`StatsWriterPlugin(opts)`](#statswriterplugin-opts-)\n\n### `StatsWriterPlugin(opts)`\n\n- **opts** (`Object`) options\n- **opts.filename** (`String|Function`) output file name (Default: `\"stats.json\"`)\n- **opts.fields** (`Array`) fields of stats obj to keep (Default: `[\"assetsByChunkName\"]`)\n- **opts.stats** (`Object|String`) stats config object or string preset (Default: `{}`)\n- **opts.transform** (`Function|Promise`) transform stats obj (Default: `JSON.stringify()`)\n- **opts.emit** (`Boolean`) add stats file to webpack output? (Default: `true`)\n\nStats writer module.\n\nStats can be a string or array (we'll have an array due to source maps):\n\n```js\n\"assetsByChunkName\": {\n  \"main\": [\n    \"cd6371d4131fbfbefaa7.bundle.js\",\n    \"../js-map/cd6371d4131fbfbefaa7.bundle.js.map\"\n  ]\n},\n```\n\n**`fields`, `stats`**\n\nThe stats object is **big**. It includes the entire source included in a bundle. Thus, we default `opts.fields` to `[\"assetsByChunkName\"]` to only include those. However, if you want the _whole thing_ (maybe doing an `opts.transform` function), then you can set `fields: null` in options to get **all** of the stats object.\n\nYou may also pass a custom stats config object (or string preset) via `opts.stats` in order to select exactly what you want added to the data passed to the transform. When `opts.stats` is passed, `opts.fields` will default to `null`.\n\nSee:\n\n- https://webpack.js.org/configuration/stats/#stats\n- https://webpack.js.org/api/node/#stats-object\n\n**`filename`**\n\nThe `opts.filename` option can be a file name or path relative to `output.path` in webpack configuration. It should not be absolute. It may also be a function, in which case it will be passed the current compiler instance and expected to return a filename to use.\n\n**`transform`**\n\nBy default, the retrieved stats object is `JSON.stringify`'ed:\n\n```javascript\nnew StatsWriterPlugin({\n  transform(data) {\n    return JSON.stringify(data, null, 2);\n  },\n});\n```\n\nBy supplying an alternate transform you can target _any_ output format. See [`test/scenarios/webpack5/webpack.config.js`](test/scenarios/webpack5/webpack.config.js) for various examples including Markdown output.\n\n- **Warning**: The output of `transform` should be a `String`, not an object. On Node `v4.x` if you return a real object in `transform`, then webpack will break with a `TypeError` (See [#8](https://github.com/FormidableLabs/webpack-stats-plugin/issues/8)). Just adding a simple `JSON.stringify()` around your object is usually what you need to solve any problems.\n\n**Internal notes**\n\nIn modern webpack, the plugin uses the [`processAssets`](https://webpack.js.org/api/compilation-hooks/#processassets) compilation hook if available when adding the stats object file to the overall compilation to write out along with all the other webpack-built assets. This is the [last possible place](https://github.com/webpack/webpack/blob/f2f998b58362d5edc9945a48f8245a3347ad007c/lib/Compilation.js#L2000-L2007) to hook in before the compilation is frozen in future webpack releases.\n\nIn earlier webpack, the plugin uses the much later [`emit`](https://webpack.js.org/api/compiler-hooks/#emit) compiler hook. There are technically some assets/stats data that could be added after `processAssets` and before `emit`, but for most practical uses of this plugin users shouldn't see any differences in the usable data produced by different versions of webpack.\n\n## Maintenance Status\n\n**Active:** NearForm is actively working on this project, and we expect to continue for work for the foreseeable future. Bug reports, feature requests and pull requests are welcome.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFormidableLabs%2Fwebpack-stats-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FFormidableLabs%2Fwebpack-stats-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFormidableLabs%2Fwebpack-stats-plugin/lists"}