webpack-custom-stats-patch

1.0.1 • Public • Published

webpack-custom-stats-patch

npm version Build Status Dependency Status devDependency Status

This module provides a patched copy of webpack's Stats prototype, it extends it to allow you to inject your own custom attributes.

This could be useful when you are writing webpack plugins that generate a specific set of information that you would to pass down to your stat plugins that could be generating things like asset manifests.

For example, you may be writing a webpack plugin to generate subresource integrity hashes that get saved into some mapping into webpack's compilation, but your stats plugin has no way of retrieving the mapping because stats.toJSON() returns only a specific set of the compilation by default [1].

This plugin patches compilation.getStats() and stats.toJson().

You can also reference your custom stats via compilation.__CUSTOM_STATS.

Install

npm install webpack-custom-stats-patch --save-dev

Usage

var CustomStats = require('webpack-custom-stats-patch');
 
var customStats = new CustomStats(compilation);
 
// Add a custom stat
customStats.addCustomStat('sris', { 'main-123456789.js': 'sha512-9000' });
 
// Now when `stats.toJson()` is called in your stats plugins, the custom stat
// is available
customStats.toJson().sris
// # => { 'main-123456789.js': 'sha512-9000' });
 
// You can also view the custom stats directly in compilation
compilation.__CUSTOM_STATS
// # => {
//    sris: {
//      'main-123456789': 'sha512-9000'
//    }
// };
 
// Replace custom stats in its entirety
// Pass in a plain object
customStats.replaceCustomStats({
  sris: {
    ...
  },
 
  rails: {
    ...
  }
});

Special Thanks

LICENSE

MIT.

Readme

Keywords

Package Sidebar

Install

npm i webpack-custom-stats-patch

Weekly Downloads

126

Version

1.0.1

License

MIT

Last publish

Collaborators

  • mikechau