Awesome
<div align="center"> <img width="120" height="120" src="https://rawgit.com/stephencookdev/speed-measure-webpack-plugin/master/logo.svg" /> <h1> Speed Measure Plugin <div><sup><em>(for webpack)</em></sup></div> </h1> <!-- ALL-CONTRIBUTORS-BADGE:START --><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> <a href="https://npmjs.com/package/speed-measure-webpack-plugin"><img src="https://img.shields.io/npm/dw/speed-measure-webpack-plugin.svg" /></a> <a href="https://npmjs.com/package/speed-measure-webpack-plugin"><img src="https://img.shields.io/node/v/speed-measure-webpack-plugin.svg" /></a> <a href="https://github.com/prettier/prettier"><img src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg" /></a> <a href="#contributors"><img src="https://img.shields.io/badge/all_contributors-10-orange.svg" /></a>
<!-- ALL-CONTRIBUTORS-BADGE:END --> </div> <br>The first step to optimising your webpack build speed, is to know where to focus your attention.
This plugin measures your webpack build speed, giving an output like this:
Install
npm install --save-dev speed-measure-webpack-plugin
or
yarn add -D speed-measure-webpack-plugin
Requirements
SMP requires at least Node v6. But otherwise, accepts all webpack versions (1, 2, 3, and 4).
Usage
Change your webpack config from
const webpackConfig = {
plugins: [new MyPlugin(), new MyOtherPlugin()],
};
to
const SpeedMeasurePlugin = require("speed-measure-webpack-plugin");
const smp = new SpeedMeasurePlugin();
const webpackConfig = smp.wrap({
plugins: [new MyPlugin(), new MyOtherPlugin()],
});
and you're done! SMP will now be printing timing output to the console by default.
Check out the examples folder for some more examples.
Options
Pass these into the constructor, as an object:
const smp = new SpeedMeasurePlugin(options);
options.disable
Type: Boolean
<br>
Default: false
If truthy, this plugin does nothing at all.
{ disable: !process.env.MEASURE }
allows opt-in measurements with MEASURE=true npm run build
.
options.outputFormat
Type: String|Function
<br>
Default: "human"
Determines in what format this plugin prints its measurements
"json"
- produces a JSON blob"human"
- produces a human readable output"humanVerbose"
- produces a more verbose version of the human readable output- If a function, it will call the function with the JSON blob, and output the response
options.outputTarget
Type: String|Function
<br>
Default: console.log
- If a string, it specifies the path to a file to output to.
- If a function, it will call the function with the output as the first parameter
options.pluginNames
Type: Object
<br>
Default: {}
By default, SMP derives plugin names through plugin.constructor.name
. For some
plugins this doesn't work (or you may want to override this default). This option
takes an object of pluginName: PluginConstructor
, e.g.
const uglify = new UglifyJSPlugin();
const smp = new SpeedMeasurePlugin({
pluginNames: {
customUglifyName: uglify,
},
});
const webpackConfig = smp.wrap({
plugins: [uglify],
});
options.loaderTopFiles
Type: Number
<br>
Default: 0
You can configure SMP to include the files that take the most time per loader, when using outputFormat: 'humanVerbose'
. E.g., to show the top 10 files per loader:
const smp = new SpeedMeasurePlugin({
outputFormat: "humanVerbose",
loaderTopFiles: 10,
});
options.compareLoadersBuild
Type: Object
<br>
Default: {}
This option gives you a comparison over time of the module count and time spent, per loader. This option provides more data when outputFormat: "humanVerbose"
.
Given a required filePath
to store the build information, this option allows you to compare differences to your codebase over time. E.g.
const smp = new SpeedMeasurePlugin({
compareLoadersBuild: {
filePath: "./buildInfo.json",
},
});
options.granularLoaderData
(experimental)
Type: Boolean
<br>
Default: false
By default, SMP measures loaders in groups. If truthy, this plugin will give per-loader timing information.
This flag is experimental. Some loaders will have inaccurate results:
- loaders using separate processes (e.g.
thread-loader
) - loaders emitting file output (e.g.
file-loader
)
We will find solutions to these issues before removing the (experimental) flag on this option.
FAQ
What does general output time mean?
This tends to be down to webpack reading in from the file-system, but in general it's anything outside of what SMP can actually measure.
What does modules without loaders mean?
It means vanilla JS files, which webpack can handle out of the box.
Contributing
Contributors are welcome! π
Please check out the CONTRIBUTING.md.
Migrating
SMP follows semver. If upgrading a major version, you can consult the migration guide.
License
Contributors β¨
Thanks goes to these wonderful people (emoji key):
<!-- ALL-CONTRIBUTORS-LIST:START --> <!-- prettier-ignore-start --> <!-- markdownlint-disable --> <table> <tr> <td align="center"><a href="https://stephencookdev.co.uk/"><img src="https://avatars.githubusercontent.com/u/8496655?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Stephen Cook</b></sub></a><br /><a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/commits?author=stephencookdev" title="Code">π»</a> <a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/commits?author=stephencookdev" title="Documentation">π</a> <a href="#blog-stephencookdev" title="Blogposts">π</a> <a href="#design-stephencookdev" title="Design">π¨</a> <a href="#question-stephencookdev" title="Answering Questions">π¬</a> <a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/pulls?q=is%3Apr+reviewed-by%3Astephencookdev" title="Reviewed Pull Requests">π</a></td> <td align="center"><a href="https://scarletsky.github.io/"><img src="https://avatars.githubusercontent.com/u/2386165?v=4?s=100" width="100px;" alt=""/><br /><sub><b>scarletsky</b></sub></a><br /><a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/commits?author=scarletsky" title="Code">π»</a></td> <td align="center"><a href="https://github.com/wayou"><img src="https://avatars.githubusercontent.com/u/3783096?v=4?s=100" width="100px;" alt=""/><br /><sub><b>ηγγ</b></sub></a><br /><a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/commits?author=wayou" title="Code">π»</a> <a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/issues?q=author%3Awayou" title="Bug reports">π</a></td> <td align="center"><a href="https://github.com/ThomasHarper"><img src="https://avatars.githubusercontent.com/u/3199791?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Thomas Bentkowski</b></sub></a><br /><a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/commits?author=ThomasHarper" title="Documentation">π</a></td> <td align="center"><a href="https://github.com/alan-agius4"><img src="https://avatars.githubusercontent.com/u/17563226?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Alan Agius</b></sub></a><br /><a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/commits?author=alan-agius4" title="Code">π»</a> <a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/issues?q=author%3Aalan-agius4" title="Bug reports">π</a></td> <td align="center"><a href="https://daix.me/"><img src="https://avatars.githubusercontent.com/u/1396511?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ximing</b></sub></a><br /><a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/commits?author=NdYAG" title="Code">π»</a> <a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/issues?q=author%3ANdYAG" title="Bug reports">π</a></td> <td align="center"><a href="https://twitter.com/lihautan"><img src="https://avatars.githubusercontent.com/u/2338632?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tan Li Hau</b></sub></a><br /><a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/commits?author=tanhauhau" title="Code">π»</a> <a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/issues?q=author%3Atanhauhau" title="Bug reports">π</a> <a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/commits?author=tanhauhau" title="Tests">β οΈ</a></td> </tr> <tr> <td align="center"><a href="https://github.com/ZauberNerd"><img src="https://avatars.githubusercontent.com/u/249542?v=4?s=100" width="100px;" alt=""/><br /><sub><b>BjΓΆrn Brauer</b></sub></a><br /><a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/commits?author=ZauberNerd" title="Code">π»</a> <a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/issues?q=author%3AZauberNerd" title="Bug reports">π</a></td> <td align="center"><a href="https://github.com/The-Only-Matrix"><img src="https://avatars.githubusercontent.com/u/61681157?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Suraj Patel</b></sub></a><br /><a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/commits?author=The-Only-Matrix" title="Code">π»</a></td> <td align="center"><a href="https://github.com/hanzooo"><img src="https://avatars.githubusercontent.com/u/16368939?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jm</b></sub></a><br /><a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/commits?author=hanzooo" title="Code">π»</a> <a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/issues?q=author%3Ahanzooo" title="Bug reports">π</a> <a href="https://github.com/stephencookdev/speed-measure-webpack-plugin/commits?author=hanzooo" title="Tests">β οΈ</a></td> </tr> </table> <!-- markdownlint-restore --> <!-- prettier-ignore-end --> <!-- ALL-CONTRIBUTORS-LIST:END -->This project follows the all-contributors specification. Contributions of any kind welcome!