• Stars
    star
    241
  • Rank 167,643 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Mad metrics for your rollup bundles, know all the things

SWUbanner

rollup-plugin-analyzer

Mad metrics for your rollup bundles, know all the things

npm Travis (.com) Dependents (via libraries.io) npm

TOC

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
      • This only suppresses the modules details, it does not affect the summary output
      • If you would like it to filter from summary info as well set filterSummary to true
    • notes: Function receives module object specified below, should return boolean
  • filterSummary - optional
    • type: Boolean
    • default: false
    • description: If true the filter and limit options will also remove any filtered out module data from the summary
  • 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
            • renderedExports (Array) - list of used named exports
            • removedExports (Array) - list of unused named exports

FAQ

Why is the reported size not the same as the file on disk?

This module is geared towards the details of the individual modules that make up the bundle and their relative impact to bundle size. That's a detailed way of saying, it doesn't really care about size on disk. There are other options which focus on size on disk as well as delivery size which can be used alongside this module (or in place of if your concern is not per module impact). In particular rollup-plugin-size-snapshot seems like a great option for that.

Getting a bit further into the details, rather than just intent, of why the reported size differs from that on disk. We get the module data from Rollup which reports it after chunk (module) resolution and tree-shaking, but before post-processing (such as minification and compression). We then add the sizes of each of those modules together, this is the bundle size that we report.

That means it won't account for post-processing from other plugins and also won't account for post-processing by Rollup itself, which includes boilerplate / shims depending on what the output format is (CJS, ESM, iife, etc...).

Why am I seeing multiple analysis outputs emitted?

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.

One way to manipulate the number of reports in this scenario is through the onAnalysis callback option:

// Track iterations over output files
let analyzePluginIterations = 0;

export default {
  input: 'myIsomorphicModule.js',
  output: [
    {
      name: 'myIsomorphicModule',
      format: 'cjs',
      entryFileNames: '[name].cjs'
    },
    {
      name: 'myIsomorphicModule',
      format: 'es',
      entryFileNames: '[name].mjs'
    }
  ],
  plugins: [
    analyze({
      onAnalysis: () => {
        if (analyzePluginIterations > 0) {
          throw ''; // We only want reports on the first output
        }
        analyzePluginIterations++;
      }
    })
  ]
}

License

MIT Β© Andrew Carpenter

More Repositories

1

jquery-video-lightning

Turn any element into a lightbox or popover link for Youtube and Vimeo videos.
JavaScript
52
star
2

rollup-analyzer

Analyze file sizes of rollup bundled imports
JavaScript
17
star
3

wm-pricer

Check WalMart's local store prices
JavaScript
11
star
4

leven-sort

Simply sort by similarity, starring Levenshtein via leven
JavaScript
9
star
5

docxmarks

Super simple bookmark replacement / mail merge for docx files
JavaScript
8
star
6

redmine_on_debian

Setup Redmine On Debian with PG, Unicorn, and Nginx in a flash.
Shell
7
star
7

rapplication

Rapping JavaScript source code over Wu-Tang Clan beat (Tearz)
JavaScript
7
star
8

eafd

When you just don't have the words. Snoop does.
JavaScript
6
star
9

check-for-uri-handler

Detect from browser whether custom URI has an installed handler
JavaScript
6
star
10

rollup-analyzer-plugin

Analyze file sizes of rollup bundled imports
JavaScript
5
star
11

mvt

βœ… Minimum Viable Testing framework
JavaScript
5
star
12

oneclick-update

Simple installer downloads and update server
JavaScript
4
star
13

tiny-params

A tiny URL param parser, suitable for server or browser
JavaScript
4
star
14

go-bin

Get GO binaries by version tag
JavaScript
3
star
15

ngo

Run Go commands from Node or CLI, Go env not required
JavaScript
3
star
16

scrud

SCRUD API server, fast, lite, capable
JavaScript
3
star
17

gitignored-cleanup

Batch remove git ignored files from version control
Shell
3
star
18

pg-ears

Resilient Postgres listen client
JavaScript
3
star
19

song-structure

Get rough idea on potential song structures from the CLI
JavaScript
2
star
20

miss.js

Make it simple stupid. Web app walkthroughs for maximum user conversion.
JavaScript
2
star
21

singleton-dom-events

One event to rule... err that one thing. Making scope complex DOM events safe since 2016
JavaScript
2
star
22

rollup-plugin-resolve-snabbdom

Extremely crude "just make it work" resolution for Snabbdom >= 1.0.0
JavaScript
1
star
23

oneclick-release-test

Just a repo to test release strategies
JavaScript
1
star
24

jao

Just an object, seriously, that's all this is
JavaScript
1
star
25

pico-ms

Incy wincy millisecond converter for days, hours, minutes, or seconds
JavaScript
1
star
26

sdfg

Random-ast CLI bs'es
JavaScript
1
star
27

bock

Bock is a strong lager (logger) of German (US) origin
JavaScript
1
star
28

get-scrud

Client for SCRUD style rest APIs
JavaScript
1
star
29

hoy

Cached breakdown of today's text components
JavaScript
1
star
30

ascii-modifiers-map

Simple mapping of some sans-serif MathML characters to their plain counterparts
JavaScript
1
star
31

doesdev

1
star
32

you-be-my-sun

Make one DOM element hug another while staying closest to page center
JavaScript
1
star
33

ricks-bricks

Execute cb if called X times within X ms and hasn't been run in X ms
JavaScript
1
star
34

rage-route

Tiny, feature lite, super basic client router
JavaScript
1
star
35

rollup-config-analyzer

Mad metrics for your rollup bundles, know all the things
JavaScript
1
star
36

pgmq

Simple messaging with PostgreSQL
JavaScript
1
star