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

bundlecheck

v1.0.1

Published

Check your application's build size and take code-splitting into account

Downloads

69

Readme

CircleCI codecov

Check the sizes of your code-splitted bundles. Any file, a lot of predefined rules and fully customized rules can be added.

Motivation

Since the beginning days, my number one choice was Bundlesize. Not because it is very customizable, but it worked.

While the number of mobile devices is increasing and performance is crucial to a lot of companies, bundles get split in several files.

This lead to more problems with bundlesize, because one can only specify a maxSize which was not sufficient to me anylonger.

Install

yarn add bundlecheck --dev
npm install bundlecheck --save-dev

Get Started

All sizes are in KiloByte

Create a basic configuration file with the following content in the root of your project and call it .bundlecheck.config.js.

module.exports = {
  relativeTo: '.',
  cwd: '.',
  observe: [
    {
      paths: ['**'],
      rules: [{ every: [0.01, 0.5] }],
    },
  ],
}

Inside your package.json add this to your scripts section:

  "scripts": {
    "bundlecheck": "bundlecheck"
  }

CLI Options

Specify a config file: --configfile or -cf

Documentation

General Configuration

  • cwd Specifies a root folder from where to find all paths
  • relativeTo Used to make cwd relative to this specified path
  • observe An array of observable paths on which rules can be applied
  • rules: An array of rules that are tested against every entry in observe
  • ignore: An array of fast-glob paths that should be ignored

Observe Entry Configuration

Use a predefined check function

observe: [
  {
    paths: ['**.js'] // Use glob patter (fast-glob)
    rules: [
      every: [0.1, 5], // Any file matched has to be between 100 Bytes and 5 KiloBytes big
      sum: [0.001], // The sum of all matching files has to be exactly 1 Byte
      mean: [,0.05], // Averaging matched file sizes have to be below 50 Bytes
      deviation [1, 2] // Defining the standard deviation of all matched files, so there has to be a difference between all files between 1 and 2 KiloByte
    ]
  }
]

Defining a custom check function

Multiple rules inside of one observe entry are treated with a boolean AND.

observe: [
  {
    paths: ['**.js']
    rules: [
      () => ({
        result: true,
        message: 'This will always result to true',
      }),
      (sizeMap) => {
        const result = sizeMap.reduce((s, [path, size]) => s + size, 0) <= 0.2;
        return {
          result,
          message: result ? 'All Good' :
            `Sum of files ${sizeMap.map(([ name ]) => name).join(' ')} too big`,
        }
      },
    ]
  }
]

Example Configurations

NextJS

Contents of a configuration file used within NextJS

const fs = require('fs');

const buildId = fs.readFileSync('dist/BUILD_ID', 'utf8');

module.exports = {
  relativeTo: '.',
  cwd: 'dist',
  observe: [
    {
      paths: [`server/static/${buildId}/pages/**.js`],
      rules: [{ every: [0, 65] }]
    },
    {
      paths: [`static/css/**.css`],
      rules: [{ every: [0, 2.5], sum: [0, 3] }]
    },
    {
      paths: [`static/chunks/!(commons)*.js`],
      rules: [{ every: [0, 0.2] }]
    },
    {
      paths: [`static/chunks/commons*.js`],
      rules: [{ every: [0, 235] }]
    },
    {
      paths: [`static/${buildId}/pages/!(_app)*.js`],
      rules: [{ every: [0, 100], sum: [0, 120] }]
    },
    {
      paths: [`static/${buildId}/pages/_app.js`],
      rules: [{ every: [120, 130] }]
    },
    {
      paths: ['static/runtime/main-*.js', 'static/runtime/polyfills-*.js', 'static/runtime/webpack-*.js'],
      rules: [{ every: [0, 15], sum: [20, 25] }]
    },
  ],
};

Yet to come

The following features are planned:

  • Fully log successes and errors (currently only errors are displayed)
  • Create a Webpack loader in order to integrate Bundlecheck within the build process
  • Compare measured size against last build on a specific branch
  • Make use of Github PR checks
  • Support other config file formats than JS