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

rollup-plugin-output-size

v1.4.2

Published

A Rollup plugin that displays output bundle sizes.

Downloads

5,733

Readme

rollup-plugin-output-size

npm Node.js CI

A Rollup plugin that displays output bundle sizes.

This project was inspired by rollup-plugin-bundle-size.

rollup-plugin-output-size example output

Install

npm install --save-dev rollup-plugin-output-size

Usage

// ESM
import outputSize from 'rollup-plugin-output-size';

// CommonJS
const { outputSize } = require('rollup-plugin-output-size');

Use the plugin, example rollup.config.js:

import outputSize from 'rollup-plugin-output-size';

export default {
  input: 'index.js',
  output: { dir: 'dist' },
  plugins: [outputSize(/* plugin options */)]
};

Options

You can change and override the behavior of this plugin through its options. Note that all options are optional.

hide

Type: boolean | OutputType[] Default: false

Disable output types display.

Set to true to disable output for all output types, or set an array to specify which output types will not be displayed.

Output types are: asset, chunk, and entry.

Note: Both chunk and entry output types are OutputChunks but entry chunks have isEntry values of true.

This option does not affect summary output.

gzip

Type: boolean | OutputType[] Default: true

Get gzipped sizes of output.

Set to false to skip getting gzipped size, or set an array to only get gzipped sizes of specified output types.

silent

Type: boolean Default: false

Disable output. This will also skip the handle and summary callbacks.

summary

Type: boolean | 'always' | SummaryCallback Default: true

Display summary output.

  • Set to false to disable summary output.
  • Set to 'always' to force summary output even if there is only one (1) output.
  • Set a callback to override default summary output.

See types in summary.types.ts.

[!NOTE]

The total gzip size of the summary output may not be entirely accurate as it is only the sum of all the individual output gzip sizes. If you need a more accurate size, you can use archiver to create an archive with all output contents and get the gzip size of that instead.

handle

Type: (info: OutputInfo, output: OutputAsset | OutputChunk) => void | Promise<void>

Override the default logging of output info.

The second argument output is the current Rollup output asset or chunk to log, while the first argument is the OutputInfo.

See types in output.types.ts.

Other Utilities

This package also includes some utility functions that you may find helpful, especially when making use of the handle and summary options.

format

Type: (info: OutputInfo) => string

Used to get the default display format of output info.

import outputSize, { format } from 'rollup-plugin-output-size';

export default {
  input: 'index.js',
  output: { dir: 'dist' },
  plugins: [
    outputSize({
      handle(info) {
        console.log(format(info));
      }
    })
  ]
};
[{type}] {path} is {hSize} → {gzip.hSize} (gzip)

gzip (util)

Type: (input: string | Uint8Array) => Promise<Size>

Used to get the gzipped size of input.

import outputSize, { gzip } from 'rollup-plugin-output-size';

export default {
  input: 'index.js',
  output: { dir: 'dist' },
  plugins: [
    outputSize({
      gzip: false,
      async handle(info, output) {
        const data = output.type === 'chunk' ? output.code : output.source;
        const gzipInfo = await gzip(data);
        console.log(info.path, gzipInfo);
      }
    })
  ]
};

summarize

Type: (summary: Summary) => string

Used to get the default display format of summary info.

import outputSize, { summarize } from 'rollup-plugin-output-size';

export default {
  input: 'index.js',
  output: { dir: 'dist' },
  plugins: [
    outputSize({
      summary(summary) {
        console.log(summarize(summary));
      }
    })
  ]
};
[total] {entry.hSize} + {chunk.hSize} + {asset.hSize} = {total.hSize}
[total] {gzip.entry.hSize} + {gzip.chunk.hSize} + {gzip.asset.hSize} = {gzip.total.hSize} (gzip)

License

Licensed under the MIT License.