FormidableLabs/webpack-stats-plugin

Name: webpack-stats-plugin

Owner: Formidable

Description: Webpack stats plugin for build information, file manifests, etc.

Created: 2015-02-08 20:54:04.0

Updated: 2018-01-10 16:52:41.0

Pushed: 2017-09-12 21:30:09.0

Homepage: null

Size: 60

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Webpack Stats Plugin

Build Status

This plugin will ingest the webpack stats object, process / transform the object and write out to a file for further consumption.

The most common use case is building a hashed bundle and wanting to programmatically refer to the correct bundle path in your Node.js server.

Installation

The plugin is available via npm:

m install --save webpack-stats-plugin
Examples

You can see lots of examples at demo/webpack.config.js.

Basic
StatsWriterPlugin = require("webpack-stats-plugin").StatsWriterPlugin;

le.exports = {
ugins: [
// Everything else **first**.

// Write out stats file to build directory.
new StatsWriterPlugin({
  filename: "stats.json" // Default
})


Custom Transform Function

The transform function has a signature of:


ransform skeleton.

param {Object} data           Stats object
param {Object} opts           Options
param {Object} opts.compiler  Current compiler instance
returns {String}              String to emit to file

tion (data, opts) {}

which you can use like:

StatsWriterPlugin = require("webpack-stats-plugin").StatsWriterPlugin;

le.exports = {
ugins: [
new StatsWriterPlugin({
  transform: function (data, opts) {
    return JSON.stringify({
      main: data.assetsByChunkName.main[0],
      css: data.assetsByChunkName.main[1]
    }, null, 2);
  }
})


Plugins
StatsWriterPlugin(opts)

Stats writer module.

Stats can be a string or array (we"ll have array from using source maps):

etsByChunkName": {
ain": [
"cd6371d4131fbfbefaa7.bundle.js",
"../js-map/cd6371d4131fbfbefaa7.bundle.js.map"


Note: The 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.

See:

filename: The opts.filename option can be a file name or path relative to output.path in webpack configuration. It should not be absolute.

transform: By default, the retrieved stats object is JSON.stringify'ed but by supplying an alternate transform you can target any output format. See demo/webpack.config.js for various examples including Markdown output.

Contributions

Contributions welcome! Make sure to pass $ gulp check.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.