1 | Webpack Stats Plugin
|
2 | ====================
|
3 |
|
4 | [![Build Status][trav_img]][trav_site]
|
5 |
|
6 | This plugin will ingest the webpack
|
7 | [stats](https://github.com/webpack/docs/wiki/node.js-api#stats) object,
|
8 | process / tranform the object and write out to a file for further consumption.
|
9 |
|
10 | The most common use case is building a hashed bundle and wanting to
|
11 | programmatically referring to the correct bundle path in your Node.js server.
|
12 |
|
13 | ## Installation
|
14 |
|
15 | The plugin is available via [npm](https://www.npmjs.com/package/webpack-stats-plugin):
|
16 |
|
17 | ```
|
18 | $ npm install --save webpack-stats-plugin
|
19 | ```
|
20 |
|
21 | ## Examples
|
22 |
|
23 | ### Stats Writer Plugin
|
24 |
|
25 | ```js
|
26 | var StatsWriterPlugin = require("webpack-stats-plugin").StatsWriterPlugin;
|
27 |
|
28 | module.exports = {
|
29 | plugins: [
|
30 | // Everything else **first**.
|
31 |
|
32 | // Write out stats file to build directory.
|
33 | new StatsWriterPlugin({
|
34 | filename: "stats.json" // Default
|
35 | })
|
36 | ]
|
37 | }
|
38 | ```
|
39 |
|
40 | ## Plugins
|
41 |
|
42 | * [`StatsWriterPlugin(opts)`](#statswriterplugin-opts-)
|
43 |
|
44 | ### `StatsWriterPlugin(opts)`
|
45 | * **opts** (`Object`) options
|
46 | * **opts.filename** (`String`) output file name (Default: "stat.json")
|
47 | * **opts.fields** (`Array`) fields of stats obj to keep (Default: \["assetsByChunkName"\])
|
48 | * **opts.transform** (`Function`) transform function of stats object before writing
|
49 |
|
50 | Stats writer module.
|
51 |
|
52 | Stats can be a string or array (we"ll have array from using source maps):
|
53 |
|
54 | ```js
|
55 | "assetsByChunkName": {
|
56 | "main": [
|
57 | "cd6371d4131fbfbefaa7.bundle.js",
|
58 | "../js-map/cd6371d4131fbfbefaa7.bundle.js.map"
|
59 | ]
|
60 | },
|
61 | ```
|
62 |
|
63 | **Note**: The stats object is **big**. It includes the entire source included
|
64 | in a bundle. Thus, we default `opts.fields` to `["assetsByChunkName"]` to
|
65 | only include those. However, if you want the _whole thing_ (maybe doing an
|
66 | `opts.transform` function), then you can set `fields: null` in options to
|
67 | get **all** of the stats object.
|
68 |
|
69 | See:
|
70 | - http://webpack.github.io/docs/long-term-caching.html#get-filenames-from-stats
|
71 | - https://github.com/webpack/docs/wiki/node.js-api#stats
|
72 |
|
73 | **Note - `filename`**: The `opts.filename` option can be a file name or path relative to
|
74 | `output.path` in webpack configuration. It should not be absolute.
|
75 |
|
76 | ## Contributions
|
77 |
|
78 | Contributions welcome! Make sure to pass `$ gulp check`.
|
79 |
|
80 | [trav]: https://travis-ci.org/
|
81 | [trav_img]: https://api.travis-ci.org/FormidableLabs/webpack-stats-plugin.svg
|
82 | [trav_site]: https://travis-ci.org/FormidableLabs/webpack-stats-plugin
|