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

cb-rollup-plugin-analyzer

v3.2.2-2

Published

Mad metrics for your rollup bundles, know all the things

Downloads

13

Readme

rollup-plugin-analyzer NPM version Code Style Build Status Supported Node Versions

Mad metrics for your rollup bundles, know all the things

rollup-plugin-analyzer

See what's bloating your bundle, how treeshaking has treated you, and other great stuff. Perfect for console printing an analysis of your bundle or integrating in your CI workflows.

Comes in two scrumptious flavors:

rollup-plugin-analyzer

Adding as a plugin to your rollup config or build script will allow you to print a well formatted analysis to the console upon bundling or get a full analysis object for CI purposes.

rollup-config-analyzer

If using Rollup's CLI to bundle with no additional config, pass -c node:rollup-config-analyzer to print a well formatted analysis to your console.

Install

$ npm install --save-dev rollup-plugin-analyzer

Usage

Importing or Requiring

Import as ES Module

import analyze from 'rollup-plugin-analyzer'

Requiring as CJS

const analyze = require('rollup-plugin-analyzer')

Usage from rollup config

export default {
  entry: 'module.js',
  dest: 'index.js',
  format: 'cjs',
  plugins: [analyze()]
}

Usage from build script

rollup({
  entry: 'main.js',
  plugins: [analyze()]
}).then(...)

CI usage example

const limitBytes = 1e6

const onAnalysis = ({ bundleSize }) => {
  if (bundleSize < limitBytes) return
  console.log(`Bundle size exceeds ${limitBytes} bytes: ${bundleSize} bytes`)
  return process.exit(1)
}

rollup({
  entry: 'main.js',
  plugins: [analyze({ onAnalysis, skipFormatted: true })]
}).then(...)

results

logged to console on rollup completion

-----------------------------
Rollup File Analysis
-----------------------------
bundle size:    2.809 KB
original size:  11.436 KB
code reduction: 75.44 %
module count:   5

█████████████████████████████████████████████░░░░░
file:            /virtual-insanity.js
bundle space:    90.64 %
rendered size:   2.546 KB
original size:   2.57 KB
code reduction:  0.93 %
dependents:      1
  - /jamiroquai.js

██░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
file:            /bundle-a.js
bundle space:    4.27 %
rendered size:   120 Bytes
original size:   309 Bytes
code reduction:  61.17 %
dependents:      0

█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
file:            /jamiroquai.js
bundle space:    2.95 %
rendered size:   83 Bytes
original size:   169 Bytes
code reduction:  50.89 %
dependents:      1
  - /the-alphabet-but-incomplete.js
...

results (with summaryOnly enabled)

-----------------------------
Rollup File Analysis
-----------------------------
bundle size:    2.809 KB
original size:  11.436 KB
code reduction: 75.44 %
module count:   5

/virtual-insanity.js
█████████████████████████████████████████████░░░░░ 90.64 % (2.546 KB)
/bundle-a.js
██░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 4.27 % (120 Bytes)
/jamiroquai.js
█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 2.95 % (83 Bytes)
/the-alphabet-but-incomplete.js
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 1.17 % (33 Bytes)
/the-declaration-of-independence.js
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 0.96 % (27 Bytes)

Options

  • stdout - optional
    • type: Boolean
    • default: false
    • description: Print to stdout (console.log) instead of stderr (console.error)
  • limit - optional
    • type: Number
    • default: null
    • description: Limit number of files to output analysis of, sorted by DESC size
  • filter - optional
    • type: Array | String | Function
    • default: null
    • description: Filter module to output in analysis results.
      • If a string is passed, checks if module name contains the string. If array it checks the same for each string in the array. If function, return a boolean to indicate if a module should be in analysis results.
    • notes: Function receives module object specified below, should return boolean
  • root - optional
    • type: String
    • default: process.cwd()
    • description: Application directory, used to display file paths relatively
  • hideDeps - optional
    • type: Boolean
    • default: false
    • description: Don't itemize dependents in the formatted output
  • showExports - optional
    • type: Boolean
    • default: false
    • description: Show used and unused exports
  • summaryOnly - optional
    • type: Boolean
    • default: false
    • description: Only output bundle summary and module usage bar graphs
  • skipFormatted - optional
    • type: Boolean
    • default: false
    • description: Don't output formatted string
  • writeTo - optional
    • type: Function
    • default: null
    • description: Callback to be invoked with formatted string
    • function will be invoked with:
      • analysisString (String)
  • transformModuleId - optional
    • type: Function
    • default: null
    • description: Modify module ids
    • function will be invoked with:
      • id (String) - path of module / rollup module id
    • function should return:
      • id (String) - desired final module id to display in analysis results
    • example: (id) => id.replace(/^\0(?:commonjs-proxy:)?/, '')
  • onAnalysis - optional
    • type: Function
    • default: null
    • description: Callback to be invoked with analysis object
    • function will be invoked with:
      • analysisObject (Object)
        • bundleSize (Number) - rendered bundle size in bytes
        • bundleOrigSize (Number) - original bundle size in bytes
        • bundleReduction (Number) - percentage of rendered bundle size reduction
        • moduleCount (Number) - Count of all included modules
        • modules (Array) - array of module analysis objects
          • module (Object)
            • id (String) - path of module / rollup module id
            • size (Number) - size of rendered module code in bytes
            • origSize (Number) - size of module's original code in bytes
            • dependents (Array) - list of dependent module ids / paths
            • percent (Number) - percentage of module size relative to entire bundle
            • reduction (Number) - percentage of rendered size reduction
            • usedExports (Array) - list of used named exports
            • unusedExports (Array) - list of unused named exports

Other considerations

Rollup allows you to output to multiple files. If you are outputting to multiple files you will get a distinct analysis for each output file. Each analysis will contain data on the files imported by the respective target.

License

MIT © Andrew Carpenter