npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@megafon/chunk-sizes-webpack-plugin

v1.0.0

Published

Webpack plugin for collecting and reporting chunks sizes in OpenMetrics format.

Downloads

926

Readme

ChunkSizesWebpackPlugin

Webpack plugin for collecting and reporting chunks sizes in OpenMetrics format. Applicable for gitlab metrics feature.

Plugin supports webpack 4 and webpack 5.

Usage

Installation

$ yarn add -D chunk-sizes-webpack-plugin

Webpack configuration

const { ChunkSizesWebpackPlugin } = require('chunk-sizes-webpack-plugin');

module.exports = [
    {
        ...,
        plugins: [
            new ChunkSizesWebpackPlugin(),
        ],
    }
];

Plugin options

All parameters are optional.

| option | type | default | description | |----------------|--------------------------|-------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------| | outputFilename | string | chunk_sizes.txt | Report file name. | | outputFolder | string | Webpack's config output.path. | Report destination folder. | | overwrite | boolean | true | Overwrite file on report generation. | | customLabels | Record<string, string> | {} | Additional custom labels in format: { labelName1: value1, labelName2: value2 }. Values will be appended in every entry's labels list. | | metricName | string | chunk_size_<unit name> | Metric custom name. Default example: for unit = kb metric name will be chunk_size_kilobytes. | | chunkLabelName | string | chunk | Chunk label name. | | unit | mb, kb, B | kb | Units for metric output. Supported values: - mb (megabytes) - kb (kilobytes) - B (bytes) |

Chunks labels

For chunk name definition webpack uses entry's property name by default. main will be used by default if this name is missing. This can lead to metrics duplication in case of several webpack configurations in one build.

Possible solutions:

  • Set up names for all entries
  • Use customLabels parameter

Report file

Plugin will overwrite report file on every run by default. In case of several webpack configurations in one build use overwrite = false and remove report file before next build manually.

Examples

Demo configuration.

Includes two builds:

  1. entry (main) with lazily-loaded modules (chunkOne and chunkTwo)
  2. simple entry (myFavoriteEntry)
  • Note: option overwrite: false should be added in every example bellow because of two builds in one config.
Defaults
// for both entries
new ChunkSizesWebpackPlugin({
    overwrite: false,
})
chunk_size_kilobytes{chunk="main"} 2.88
chunk_size_kilobytes{chunk="chunkTwo"} 0.09
chunk_size_kilobytes{chunk="chunkOne"} 0.09
chunk_size_kilobytes{chunk="myFavoriteEntry"} 0.08
With custom labels
// main entry
new ChunkSizesWebpackPlugin({
    overwrite: false,
    customLabels: {
        customLabel: 'custom-value',
    },
})

// myFavoriteEntry
new ChunkSizesWebpackPlugin({
    overwrite: false,
    customLabels: {
        bundle: 'myFavoriteBundle',
    },
})
chunk_size_kilobytes{bundle="myFavoriteBundle",chunk="myFavoriteEntry"} 0.08
chunk_size_kilobytes{customLabel="custom-value",chunk="main"} 2.88
chunk_size_kilobytes{customLabel="custom-value",chunk="chunkTwo"} 0.09
chunk_size_kilobytes{customLabel="custom-value",chunk="chunkOne"} 0.09
With custom metric name
// for both entries
new ChunkSizesWebpackPlugin({
    overwrite: false,
    metricName: 'custom_metric_name',
})
custom_metric_name{chunk="myFavoriteEntry"} 0.08
custom_metric_name{chunk="main"} 2.88
custom_metric_name{chunk="chunkTwo"} 0.09
custom_metric_name{chunk="chunkOne"} 0.09
With custom chunk label name
// for both entries
new ChunkSizesWebpackPlugin({
    overwrite: false,
    chunkLabelName: 'particle',
})
chunk_size_kilobytes{particle="myFavoriteEntry"} 0.08
chunk_size_kilobytes{particle="main"} 2.88
chunk_size_kilobytes{particle="chunkTwo"} 0.09
chunk_size_kilobytes{particle="chunkOne"} 0.09
With bytes in unit
// for both entries
new ChunkSizesWebpackPlugin({
    overwrite: false,
    unit: 'B',
})
chunk_size_bytes{chunk="myFavoriteEntry"} 81
chunk_size_bytes{chunk="main"} 2946
chunk_size_bytes{chunk="chunkTwo"} 93
chunk_size_bytes{chunk="chunkOne"} 92

Contributing

Follow CONTRIBUTING.md and CODE_OF_CONDUCT.md.