UNPKG

4.18 kBMarkdownView Raw
1<div align="center">
2 <img width="120" height="120" src="https://rawgit.com/stephencookdev/speed-measure-webpack-plugin/master/logo.svg" />
3 <h1>
4 Speed Measure Plugin
5 <div><sup><em>(for webpack)</em></sup></div>
6 </h1>
7
8 <a href="https://travis-ci.org/stephencookdev/speed-measure-webpack-plugin"><img src="https://travis-ci.org/stephencookdev/speed-measure-webpack-plugin.svg?branch=master" /></a>
9 <a href="https://npmjs.com/package/speed-measure-webpack-plugin"><img src="https://img.shields.io/npm/dw/speed-measure-webpack-plugin.svg" /></a>
10 <a href="https://npmjs.com/package/speed-measure-webpack-plugin"><img src="https://img.shields.io/node/v/speed-measure-webpack-plugin.svg" /></a>
11</div>
12<br>
13
14The first step to optimising your webpack build speed, is to know where to focus your attention.
15
16This plugin measures your webpack build speed, giving an output like this:
17
18![Preview of Speed Measure Plugin's output](preview.png)
19
20## Install
21
22```bash
23npm install --save-dev speed-measure-webpack-plugin
24```
25
26or
27
28```bash
29yarn add -D speed-measure-webpack-plugin
30```
31
32## Migrating
33
34SMP follows [semver](https://semver.org/). If upgrading a major version, you can consult [the migration guide](./migration.md).
35
36## Requirements
37
38SMP requires at least Node v6.
39
40## Usage
41
42Change your webpack config from
43
44```javascript
45const webpackConfig = {
46 plugins: [
47 new MyPlugin(),
48 new MyOtherPlugin()
49 ]
50}
51```
52
53to
54
55```javascript
56const SpeedMeasurePlugin = require("speed-measure-webpack-plugin");
57
58const smp = new SpeedMeasurePlugin();
59
60const webpackConfig = smp.wrap({
61 plugins: [
62 new MyPlugin(),
63 new MyOtherPlugin()
64 ]
65});
66```
67
68and you're done! SMP will now be printing timing output to the console by default.
69
70Check out the [examples folder](/examples) for some more examples.
71
72## Options
73
74Options are (optionally) passed in to the constructor
75
76```javascript
77const smp = new SpeedMeasurePlugin(options);
78```
79
80### `options.disable`
81
82Type: `Boolean`<br>
83Default: `false`
84
85If truthy, this plugin does nothing at all. It is recommended to set this with something similar to `{ disable: !process.env.MEASURE }` to allow opt-in measurements with a `MEASURE=true npm run build`
86
87### `options.outputFormat`
88
89Type: `String|Function`<br>
90Default: `"human"`
91
92Determines in what format this plugin prints its measurements
93
94 * `"json"` - produces a JSON blob
95 * `"human"` - produces a human readable output
96 * `"humanVerbose"` - produces a more verbose version of the human readable output
97 * If a function, it will call the function with the JSON blob being the first parameter, and just the response of the function as the output
98
99### `options.outputTarget`
100
101Type: `String|Function`<br>
102Default: `console.log`
103
104* If a string, it specifies the path to a file to output to.
105* If a function, it will call the function with the output as the first parameter
106
107### `options.pluginNames`
108
109Type: `Object`<br>
110Default: `{}`
111
112By default, SMP derives plugin names through `plugin.constructor.name`. For some
113plugins this doesn't work (or you may want to override this default). This option
114takes an object of `pluginName: PluginConstructor`, e.g.
115
116```javascript
117const uglify = new UglifyJSPlugin();
118const smp = new SpeedMeasurePlugin({
119 pluginNames: {
120 customUglifyName: uglify
121 }
122});
123
124const webpackConfig = smp.wrap({
125 plugins: [
126 uglify
127 ]
128});
129```
130
131### `options.granularLoaderData` _(experimental)_
132
133Type: `Boolean`<br>
134Default: `false`
135
136If truthy, this plugin will attempt to break down the loader timing data to give per-loader timing information.
137
138Points of note that the following loaders will have inaccurate results in this mode:
139
140 * loaders using separate processes (e.g. `thread-loader`) - these make it difficult to get timing information on the subsequent loaders, as they're not attached to the main thread
141 * loaders emitting file output (e.g. `file-loader`) - the time taken in outputting the actual file is not included in the running time of the loader
142
143These are restrictions from technical limitations - ideally we would find solutions to these problems before removing the _(experimental)_ flag on this options
144
145## License
146
147[MIT](/LICENSE)