JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 39177
  • Score
    100M100P100Q149034F
  • License MIT

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

Package Exports

  • sonda
  • sonda/package.json

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
  • Rspack

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
// vite.config.js

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

export default defineConfig( {
  plugins: [
    SondaRollupPlugin(),
  ],
  build: {
    sourcemap: true
  }
} );
Rollup
// 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,
} )
esbuild
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
// 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
// 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',
  filename: 'sonda-report.html',
  open: true,
  detailed: true,
  gzip: true,
  brotli: true,
} )

format

  • Type: string
  • Default: 'html'

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

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

filename

  • Type: string
  • Default: 'sonda-report.html' or 'sonda-report.json' depending on the format option

Determines the path of the generated report. The values can be either a filename, a relative path, or an absolute path.

By default, the report is saved in the current working directory.

open

  • Type: boolean
  • Default: true

Determines 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

Determines whether to read the source maps of imported modules.

By default, external dependencies that are bundled into a single file appear as a single asset in the report. When this option is enabled, the report will instead include the source files of the imported modules, if they have source maps.

Enabling this option will increase the time needed to generate the report and reduce the accuracy of estimated GZIP and Brotli sizes for individual files.

sources

  • Type: boolean
  • Default: false

Determines whether to include the source maps of the assets in the report to visualize which parts of the code contribute to the final bundle size.

⚠️ Enabling this option will significantly increase the report size and include it in the source code of the assets. If you work with proprietary code, be cautious when sharing the report. ⚠️

gzip

  • Type: boolean
  • Default: false

Determines whether to calculate the sizes of assets after compression with GZIP.

The report will include estimated compressed sizes for each file within an asset. However, unlike the compressed size of the entire asset, these individual file estimates are approximate and should be used as a general reference.

Enabling this option will increase the time needed to generate the report.

brotli

  • Type: boolean
  • Default: false

Determines whether to calculate the sizes of assets after compression with Brotli.

The report will include estimated compressed sizes for each file within an asset. However, unlike the compressed size of the entire asset, these individual file estimates are approximate and should be used as a general reference.

Enabling this option will increase the time needed to generate the report.