
Research
/Security News
Toptalโs GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptalโs GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
speed-measure-webpack-plugin
Advanced tools
Measure + analyse the speed of your webpack loaders and plugins
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.
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
]
});
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.
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:
npm install --save-dev speed-measure-webpack-plugin
or
yarn add -D speed-measure-webpack-plugin
SMP requires at least Node v6. But otherwise, accepts all webpack versions (1, 2, 3, and 4).
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.
Pass these into the constructor, as an object:
const smp = new SpeedMeasurePlugin(options);
options.disable
Type: Boolean
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
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 outputoptions.outputTarget
Type: String|Function
Default: console.log
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.loaderTopFiles
Type: Number
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
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
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:
thread-loader
)file-loader
)We will find solutions to these issues before removing the (experimental) flag on this option.
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.
It means vanilla JS files, which webpack can handle out of the box.
Contributors are welcome! ๐
Please check out the CONTRIBUTING.md.
SMP follows semver. If upgrading a major version, you can consult the migration guide.
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
FAQs
Measure + analyse the speed of your webpack loaders and plugins
The npm package speed-measure-webpack-plugin receives a total of 627,293 weekly downloads. As such, speed-measure-webpack-plugin popularity was classified as popular.
We found that speed-measure-webpack-plugin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.ย It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Threat actors hijacked Toptalโs GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.