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

sonda

v0.3.0

Published

Universal visualizer and analyzer for JavaScript and CSS bundles. Works with Vite, Rollup, webpack, and esbuild

Downloads

762

Readme

Sonda

Sonda is a universal visualizer and analyzer for JavaScript and CSS bundles. It analyzes the source maps and shows the size of each module after tree-shaking and minification to get the most accurate report.

Sonda works with the following bundlers:

  • Vite
  • Rollup
  • esbuild
  • webpack

HTML report generated by Sonda with open modal containing file details and tree map diagram in the background

Installation

Start by installing the package:

npm install sonda --save-dev

Then register the bundler-specific plugin and enable the source maps. Remember to use Sonda in development mode only.

// vite.config.js

import { defineConfig } from 'vite';
import { SondaRollupPlugin } from 'sonda';

export default defineConfig( {
  plugins: [
    SondaRollupPlugin(),
  ],
  build: {
    sourcemap: true
  }
} );
// rollup.config.js

import { defineConfig } from 'rollup';
import { SondaRollupPlugin } from 'sonda';

export default defineConfig( {
  output: {
    // Other options are skipped for brevity
    sourcemap: true,
  },
  plugins: [
    SondaRollupPlugin(),
  ]
} );

Some Rollup plugins may not support source maps by default. Check their documentation to enable them. Examples for @rollup/plugin-commonjs and rollup-plugin-styles are shown below.

commonjs( {
  sourceMap: true,
} ),
styles( {
  mode: 'extract',
  sourceMap: true,
} )
import { build } from 'esbuild';
import { SondaEsbuildPlugin } from 'sonda';

build( {
  sourcemap: true,
  plugins: [
    SondaEsbuildPlugin()
  ]
} );

Unlike for other bundlers, the esbuild plugin relies not only on source maps but also on the metafile. The plugin should automatically enable the metafile option for you, but if you get the error, be sure to enable it manually (metafile: true).

// webpack.config.js

const { SondaWebpackPlugin } = require( 'sonda' );

module.exports = {
  devtool: 'source-map',
  plugins: [
    new SondaWebpackPlugin(),
  ],
};

Internally, Sonda changes the default webpack configuration to output absolute paths in the source maps instead of using the webpack:// protocol (devtoolModuleFilenameTemplate: '[absolute-resource-path]').

// rspack.config.js

import { SondaWebpackPlugin } from 'sonda';

export default {
  devtool: 'source-map',
  plugins: [
    new SondaWebpackPlugin(),
  ],
};

Internally, Sonda changes the default Rspack configuration to output absolute paths in the source maps instead of using the webpack:// protocol (devtoolModuleFilenameTemplate: '[absolute-resource-path]').

Options

Each plugin accepts an optional configuration object with the following options. Example:

SondaRollupPlugin( {
  format: 'html',
  open: true,
  detailed: true,
  gzip: true,
  brotli: true,
} )

format

  • Type: string
  • Default: 'html'

The format of the output. The following formats are supported:

  • 'html' - HTML file with treemap
  • 'json' - JSON file

open

  • Type: boolean
  • Default: true

Whether to open the report in the default program for given file extension (.html or .json depending on the format option) after the build.

detailed

  • Type: boolean
  • Default: false

Whether to read the source maps of imported modules.

By default, external dependencies that are bundled into a single file are shown as a single asset in the report. However, when investigating tree-shaking issues, it can be useful to see individual source files of the dependencies.

Enabling this options will read the source maps of imported modules and show individual files that make up these bundles.

Enabling this option will increase the time it takes to generate the report and decrease the accuracy of the estimated GZIP and Brotli sizes of individual files.

gzip

  • Type: boolean
  • Default: false

Whether to calculate the sizes of assets after compression with GZIP.

The report will also include the estimated compressed sizes of the individual files that make up each asset. However, unlike the compressed size of the entire asset, the estimates for individual files are not completely accurate and should only be used as a reference.

Enabling this option will increase the time it takes to generate the report.

brotli

  • Type: boolean
  • Default: false

Whether to calculate the sizes of assets after compression with Brotli.

The report will also include the estimated compressed sizes of the individual files that make up each asset. However, unlike the compressed size of the entire asset, the estimates for individual files are not completely accurate and should only be used as a reference.

Enabling this option will increase the time it takes to generate the report.