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

bundle-analyzer

v0.0.6

Published

Displays a visualization of code sizes by file based on source map information.

Downloads

1,789

Readme

Bundle analyzer

Displays a visualization of code sizes by file based on source map information.

Bundle analyzer in action

File sizes displayed by this tool reflect size of transpiled minified bundled code, as calculated from source maps. Note that this tool does not take compression (i.e. gzip/brotli) into account. Compression profiles vary depending on the compression algorithm and aggressiveness setting, thus cannot be easily calculated with accuracy. For the purposes of optimization work, making an assumption that compression is applied evenly across the bundle is usually good enough.


Installation

# NPM
npm install bundle-analyzer -g

# Yarn
yarn add bundle-analyzer --global

Usage

CLI

bundle-analyzer dist-directory
  • dist-directory - Required. A directory path that contains minified Javascript files and their source maps. It's expected that source map files have the same name as their respective js files, plus a .map extension.

API

import analyzer from 'bundle-analyzer';

analyzer.start

  • const server = analyzer.start({dir: string, port: number})

    • dir: string - Required. A directory path that contains minified Javascript files and their source maps. It's expected that source map files have the same name as their respective js files, plus a .map extension.
    • port: number - Optional. Defaults to 9000. The port at which the analyzer server runs
    • returns server: {update : () => void, close: () => void}
      • server.update() - Hot-reloads the visualization
      • server.close() - Shuts down the analyzer server

analyzer.getSizes

  • const sizes = await analyzer.getSizes(dir)

    • dir: string - Required. A directory path that contains minified Javascript files and their source maps. It's expected that source map files have the same name as their respective js files, plus a .map extension.
    • returns sizes: Node {name: string, children: ?[Node], size: ?number}
      • name: string - a directory or file name
      • children: [Node] - a list of subdirectories or files
      • size: number - a size calculation based on source maps. It represents the sum of sizes of all the code originating from a single file, after transpilation, minification and bundling.

Ways to decrease file size

Bundle splitting

Typically, the simplest way to reduce the amount of code being downloaded on page load is to employ code splitting

Reduce dependencies

For example, prefer native Array methods over utility libraries such as Lodash and Ramda, and prefer tree-shaking friendly libraries over monolythic ones (e.g. date-fns vs moment.js)

Alias libraries

For example, React can often be replaced by similar libraries such as Nerv.js or Preact.

Remove polyfills

Ensure you're not polyfilling/mocking node globals


Differences from webpack-bundle-analyzer

Bundle analyzer CLI hot-reloads, and its programmatic API is designed to integrate with server push events.

Bundle analyzer uses a D3-based zoomable sunburst visualization, which provides a more accurate visual representation of size breakdowns. In addition, bundle analyzer aggregates the analysis of all bundles into a single interface, and it hot-reloads them when it detects changes in disk.

Bundle analyzer looks at source maps rather than webpack's stats.json file, so it should work with other non-Webpack tools such as Rollup or Parcel.

Bundle analyzer does not report compression estimates, since different compression algorithms and different settings give different results and the results of gzipping each section individually doesn't provide an accurate number anyways.

Differences from source-map-explorer

Both bundle analyzer and source map explorer display roughly the same information, but slightly differently. Bundle analyzer uses a D3-based zoomable sunburst visualization, which provides a more accurate visual representation of size breakdowns. In addition, bundle analyzer aggregates the analysis of all bundles into a single interface, and it hot-reloads them when it detects changes in disk.


License: MIT