CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-rollup-plugin-sizes

Show info about files/packages included with your rollup bundle

94

1.09x
Overview
Eval results
Files

task.mdevals/scenario-5/

Bundle Size Analyzer Plugin

Build a Rollup plugin that analyzes the original, unminified sizes of modules in a bundle and exports a JSON report.

Requirements

Your plugin should integrate with Rollup's build process and generate a size analysis report that captures the original source sizes of modules before any transformations or minification.

Core Functionality

Create a plugin that:

  1. Hooks into the bundle generation phase
  2. Analyzes each module in the generated bundle
  3. Records the original source size for each module (before minification/transformation)
  4. Outputs a JSON file with size analysis data

Report Format

The plugin should write a file named size-report.json to the output directory containing:

{
  "totalSize": 12345,
  "modules": [
    {
      "id": "src/main.js",
      "size": 5432
    },
    {
      "id": "node_modules/lodash/index.js",
      "size": 6913
    }
  ]
}

Where:

  • totalSize is the sum of all module original sizes
  • modules is an array of module objects sorted by size (largest first)
  • Each module has an id (module path) and size (original bytes)

Test Cases

  • When the plugin processes a bundle with three modules of sizes 100, 200, and 300 bytes, it generates a report with totalSize of 600 and modules sorted correctly @test
  • When the plugin processes a bundle with a single module, it generates a valid report with one module entry @test
  • When the plugin processes an empty bundle, it generates a report with totalSize of 0 and an empty modules array @test

Implementation

@generates

API

/**
 * Creates a Rollup plugin that analyzes original module sizes
 *
 * @returns {Object} Rollup plugin object
 */
function sizeAnalyzer() {
  // Returns a plugin object with name and generateBundle hook
}

module.exports = sizeAnalyzer;

Dependencies { .dependencies }

rollup-plugin-sizes { .dependency }

Provides bundle size analysis capabilities for Rollup.

Install with Tessl CLI

npx tessl i tessl/npm-rollup-plugin-sizes

tile.json