esbuild Bundler for Monosize

0.3.2 · active · verified Wed Apr 22

This package provides an `esbuild`-based bundler plugin for the `monosize` package size measurement tool. It enables `monosize` to use `esbuild` for creating optimized bundles, allowing developers to accurately assess the size implications of their code using a high-performance bundler. The current stable version is 0.3.2, and its release cadence is typically tied to updates in `monosize` or `esbuild` itself. Key differentiators include its seamless integration into the `monosize.config.mjs` setup, support for `esbuild`'s full configuration options via a callback, and optimized batch build modes for faster measurements compared to sequential builds. It leverages `esbuild`'s speed and efficiency to provide quick and reliable size reports.

Common errors

Warnings

Install

Imports

Quickstart

Shows how to configure `monosize.config.mjs` to use `monosize-bundler-esbuild`, including custom `esbuild` configuration such as adding a file loader for SVGs and defining environment variables.

import esbuildBundler from 'monosize-bundler-esbuild';

export default {
  // Define your entry points for monosize to measure
  fixtures: {
    'my-component-bundle': 'src/my-component.ts',
    'another-lib': 'src/another-lib/index.js'
  },
  // Configure the esbuild bundler plugin
  bundler: esbuildBundler(config => {
    // Example: Add a loader for SVG files if your components import them
    config.loader = {
      ...config.loader,
      '.svg': 'file',
    };
    // Example: Define some global constants
    config.define = {
      ...config.define,
      'process.env.NODE_ENV': JSON.stringify('production'),
    };
    // Always return the (potentially modified) config
    return config;
  }),
  // Other monosize configurations...
  output: {
    directory: './monosize-results'
  }
};

view raw JSON →