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 |
|
14 | The first step to optimising your webpack build speed, is to know where to focus your attention.
|
15 |
|
16 | This 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
|
23 | npm install --save-dev speed-measure-webpack-plugin
|
24 | ```
|
25 |
|
26 | or
|
27 |
|
28 | ```bash
|
29 | yarn add -D speed-measure-webpack-plugin
|
30 | ```
|
31 |
|
32 | ## Migrating
|
33 |
|
34 | SMP follows [semver](https://semver.org/). If upgrading a major version, you can consult [the migration guide](./migration.md).
|
35 |
|
36 | ## Requirements
|
37 |
|
38 | SMP requires at least Node v6.
|
39 |
|
40 | ## Usage
|
41 |
|
42 | Change your webpack config from
|
43 |
|
44 | ```javascript
|
45 | const webpackConfig = {
|
46 | plugins: [
|
47 | new MyPlugin(),
|
48 | new MyOtherPlugin()
|
49 | ]
|
50 | }
|
51 | ```
|
52 |
|
53 | to
|
54 |
|
55 | ```javascript
|
56 | const SpeedMeasurePlugin = require("speed-measure-webpack-plugin");
|
57 |
|
58 | const smp = new SpeedMeasurePlugin();
|
59 |
|
60 | const webpackConfig = smp.wrap({
|
61 | plugins: [
|
62 | new MyPlugin(),
|
63 | new MyOtherPlugin()
|
64 | ]
|
65 | });
|
66 | ```
|
67 |
|
68 | and you're done! SMP will now be printing timing output to the console by default.
|
69 |
|
70 | Check out the [examples folder](/examples) for some more examples.
|
71 |
|
72 | ## Options
|
73 |
|
74 | Options are (optionally) passed in to the constructor
|
75 |
|
76 | ```javascript
|
77 | const smp = new SpeedMeasurePlugin(options);
|
78 | ```
|
79 |
|
80 | ### `options.disable`
|
81 |
|
82 | Type: `Boolean`<br>
|
83 | Default: `false`
|
84 |
|
85 | If 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 |
|
89 | Type: `String|Function`<br>
|
90 | Default: `"human"`
|
91 |
|
92 | Determines 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 |
|
101 | Type: `String|Function`<br>
|
102 | Default: `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 |
|
109 | Type: `Object`<br>
|
110 | Default: `{}`
|
111 |
|
112 | By default, SMP derives plugin names through `plugin.constructor.name`. For some
|
113 | plugins this doesn't work (or you may want to override this default). This option
|
114 | takes an object of `pluginName: PluginConstructor`, e.g.
|
115 |
|
116 | ```javascript
|
117 | const uglify = new UglifyJSPlugin();
|
118 | const smp = new SpeedMeasurePlugin({
|
119 | pluginNames: {
|
120 | customUglifyName: uglify
|
121 | }
|
122 | });
|
123 |
|
124 | const webpackConfig = smp.wrap({
|
125 | plugins: [
|
126 | uglify
|
127 | ]
|
128 | });
|
129 | ```
|
130 |
|
131 | ### `options.granularLoaderData` _(experimental)_
|
132 |
|
133 | Type: `Boolean`<br>
|
134 | Default: `false`
|
135 |
|
136 | If truthy, this plugin will attempt to break down the loader timing data to give per-loader timing information.
|
137 |
|
138 | Points 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 |
|
143 | These 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)
|