What is speed-measure-webpack-plugin?
The speed-measure-webpack-plugin (SMP) is a tool designed to measure the build speed of your webpack configuration. It helps developers identify bottlenecks in their build process by providing detailed timing information for each plugin and loader used in the webpack configuration.
What are speed-measure-webpack-plugin's main functionalities?
Measure Build Speed
This feature allows you to wrap your existing webpack configuration with SMP to measure the build speed. The `wrap` method is used to wrap the configuration, and SMP will then provide detailed timing information for each part of the build process.
const SpeedMeasurePlugin = require('speed-measure-webpack-plugin');
const smp = new SpeedMeasurePlugin();
module.exports = smp.wrap({
// Your webpack configuration
entry: './src/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: 'babel-loader'
}
]
},
plugins: [
// Your plugins
]
});
Detailed Timing Information
This feature allows you to customize the output format and target for the timing information. In this example, the `outputFormat` is set to 'human' for a more readable format, and the `outputTarget` is set to `console.log` to print the timing information to the console.
const SpeedMeasurePlugin = require('speed-measure-webpack-plugin');
const smp = new SpeedMeasurePlugin({
outputFormat: 'human',
outputTarget: console.log
});
module.exports = smp.wrap({
// Your webpack configuration
entry: './src/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: 'babel-loader'
}
]
},
plugins: [
// Your plugins
]
});
Other packages similar to speed-measure-webpack-plugin
webpack-bundle-analyzer
The webpack-bundle-analyzer plugin provides a visual representation of the size of webpack output files. It helps developers understand the size of their bundles and identify large dependencies. Unlike SMP, which focuses on build speed, webpack-bundle-analyzer focuses on bundle size and composition.
webpack-dashboard
The webpack-dashboard plugin provides a terminal-based dashboard for webpack builds. It displays build progress, errors, and warnings in a more user-friendly way. While SMP focuses on measuring build speed, webpack-dashboard aims to improve the overall developer experience by providing real-time feedback during the build process.
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
Migrating
SMP follows semver. If upgrading a major version, you can consult the migration guide.
Requirements
SMP requires at least Node v6.
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
Options are (optionally) passed in to the constructor
const smp = new SpeedMeasurePlugin(options);
options.disable
Type: Boolean
Default: false
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
options.outputFormat
Type: String|Function
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 being the first parameter, and just the response of the function as the output
options.outputTarget
Type: String|Function
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
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.granularLoaderData
(experimental)
Type: Boolean
Default: false
If truthy, this plugin will attempt to break down the loader timing data to give per-loader timing information.
Points of note that the following loaders will have inaccurate results in this mode:
- 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 - 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
These are restrictions from technical limitations - ideally we would find solutions to these problems before removing the (experimental) flag on this options
License
MIT