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

@rnx-kit/esbuild-bundle-analyzer

v0.3.0

Published

EXPERIMENTAL - USE WITH CAUTION - A tool for analyzing an esbuild bundle/metafile

Downloads

11

Readme

@rnx-kit/esbuild-bundle-analyzer

Build npm version

🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧

THIS TOOL IS EXPERIMENTAL — USE WITH CAUTION

🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧

Motivation

This tool provides simple analysis of bundles based on esbuild's metafile. It allows users to analyze a bundle/metafile, compare two metafiles, and generate a limited, but compatible Webpack stats file. This file can then be used with more advanced Webpack-based analysis and comparison tools such as @mixer/webpack-bundle-compare. This tool could allow developers quickly and easily gain insights into their bundle size and composition.

Installation

yarn add @rnx-kit/esbuild-bundle-analyzer --dev

or if you're using npm

npm add --save-dev @rnx-kit/esbuild-bundle-analyzer

Usage

This tool has three commands, analyze, compare, and transform. You can find the full list of functionalities by invoking the command npx @rnx-kit/esbuild-bundle-analyzer --help.

analyze

This command will output a simple analysis of the input and output files and in-depth detail about the duplicate dependencies. This tool consumes esbuild's metafile and then analyzes the data to provide a simple analysis of the bundle. For all the duplicates the tool will present full path from the entry-point to the duplicated file to showcase why and how the duplicated files are being added in the bundle.

Generate simple analysis of a bundle by consuming esbuild's metafile:

npx @rnx-kit/esbuild-bundle-analyzer analyze <path-to-esbuild-metafile>

Along with these core options, you might want to pass the following params:

  • --show-duplicates, Boolean flag to output how each duplicated file is being added to the bundle
  • --json, Outputs the analysis in JSON format and sets the output file to write the analysis information to. If not set the analysis will be output to the console
  • --namespace, Every module has an associated namespace. By default esbuild operates in the file namespace, which corresponds to files on the file system. @rnx-kit/metro-serializer-esbuild uses the virtual:metro namespace. This flag allows you to specify the namespace of the metafile. This is useful if you want cleaner output without the namespace prefix.

A complete example of this script is the following:

npx @rnx-kit/esbuild-bundle-analyzer analyze meta.json --json --show-duplicates --namespace virtual:metro

compare

This command will compare two metafiles and outputs the difference between the two.

npx @rnx-kit/esbuild-bundle-analyzer compare --baseline <path-to-esbuild-metafile> --candidate <path-to-esbuild-metafile>

compare

This command will compare two metafiles and outputs the difference between the two.

npx @rnx-kit/esbuild-bundle-analyzer compare --baseline <path-to-esbuild-metafile> --candidate <path-to-esbuild-metafile>

This command consumes the esbuild metafile and transforms it into a compatible Webpack stats file containing only the relevant data for @mixer/webpack-bundle-compare. Then, the Webpack stats file can be consumed by @mixer/webpack-bundle-compare which presents a visual analysis of Webpack based bundles and allows you to track and compare the bundle size over time.

Generate a webpack stats file:

npx @rnx-kit/esbuild-bundle-analyzer transform <path-to-esbuild-metafile> --output <path-to-webpack-stats-file>

Then, you can upload the generated Webpack stats file to here to visualize the bundle.