@aklinker1/rollup-plugin-visualizer

中文文档
5.12.0发布于 2024/02/24MITTypeScriptCommonJS近 30 天下载 298万
原始使用文档
文档目录16 节
  1. Screenshots
  2. Installation
  3. Usage
  4. How to use generated files
  5. Sunburst
  6. Treemap
  7. Network
  8. Raw-data
  9. List
  10. Options
  11. Advanced options (touch only if you really need it):
  12. CLI
  13. Build plugin
  14. Disclaimer about generated files
  15. Upgrades
  16. Versioning

Rollup Plugin Visualizer

NPM Version Node.js CI

Visualize and analyze your Rollup bundle to see which modules are taking up space.

Screenshots

pic

Installation

npm install --save-dev rollup-plugin-visualizer

or via yarn:

yarn add --dev rollup-plugin-visualizer

Usage

Import

// es
import { visualizer } from "rollup-plugin-visualizer";
// or
// cjs
const { visualizer } = require("rollup-plugin-visualizer");

Usage with rollup (rollup.config.js)

module.exports = {
  plugins: [
    // put it the last one
    visualizer(),
  ],
};

Usage with vite (vite.config.js)

module.exports = {
  plugins: [visualizer()],
};

Usage with vite TypeScript (vite.config.ts)

import { defineConfig, type PluginOption } from 'vite'
export default defineConfig({
  plugins: [visualizer() as PluginOption],
})

Usage with SvelteKit (vite.config.js)

const config = {
  plugins: [
    visualizer({
      emitFile: true,
      filename: "stats.html",
    }),
  ],
};

export default config;

You will find 2/3 files in .svelte-kit/output dir named stats.html (see vite logs for file locations) . You can use this snippet as a starting point and change props/path. You can also generate 3 json files and combine them to one with cli util.

How to use generated files

Blue color used to to mark project-own files. This could be: written by you files or generated by build tool files.

Green color used to mark your dependencies.

Internally it just checks if file id prefix is node_modules.

All charts refresh layout on window resize.

Sunburst

This circular hierarchical diagram can help you find huge pieces of code (aka that one huge thing). If you click on some arc it will increase its and all nested arcs size for better inspection.

Treemap

This rectangular hierarchical diagram can help you find huge pieces. Just look on biggest reclangle. But also it can help you find modules included several times, they will have the same topology and relative size. If you click on reclangle it will increase in size for further inspection.

Network

This digram should help you answer for the question 'why it is included?'. After force layout stabilize all nodes, you can move it back and forth by dragging with your mouse. Gray circles are treeshakened out files.

In real life scenarious, sometimes you will see terribly connected diagrams. There is no 100% working solution for everyone, it is expected you topology will look 'terrible' and not hold on screen. To make it still visually ispectable, first remove all highly connected nodes that you see (typical examples: commonjsHelpers, tslib, react etc, basically if tooltip for the node is not hold on the screen - exclude this node), after layout stabilization you will see, your layout is not that terrible anymore and most of dependencies cluster together. Move layout to find pieces you looked for.

When you click on node it will hightlight nodes that are listed in tooltip (the files that imports current node).

Raw-data

This template produce JSON output with raw data. Normally it should be used with CLI from this plugin.

List

Output yml file with all the data, could be good idea to commit this file to track file changes.

Options

filename (string, default stats.{ext depending template}) - name of the file with diagram to generate

title (string, default Rollup Visualizer) - title tag value

open (boolean, default false) - Open generated file in default user agent

template (string, default treemap) - Which diagram type to use: sunburst, treemap, network, raw-data, list.

gzipSize (boolean, default false) - Collect gzip size from source code and display it at chart.

brotliSize (boolean, default false) - Collect brotli size from source code and display it at chart.

Advanced options (touch only if you really need it):

emitFile (boolean, default false) - Use rollup's emitFile to generate file. Useful if you want to control all output in one place (via rollup output options). This also could be usefull with svelte as it calls vite several times.

sourcemap (boolean, default false) - Use sourcemaps to calculate sizes (e.g. after UglifyJs or Terser). Always add plugin as last option.

projectRoot (string | RegExp, default process.cwd()) - This is some common root(s) path to your files. This is used to cut absolute files paths out.

include (Filter | Filter[], default undefined) - Filter for inclusion

exclude (Filter | Filter[], default undefined) - Filter for exclusion

Filter type is { bundle?: picomatchPattern, file?: picomatchPattern }

Note about include and exclude - If options.include is omitted or has zero length, filter will return true by default. Otherwise, an ID must match one or more of the picomatch patterns, and must not match any of the options.exclude patterns. This entries will not be included in stats at all.

Include and Exclude

Include and exclude filters uses glob matchers with picomatch. In UI you can do such combinations (both exclude and include):

  • Filter bundle and file in one string
    • translation-*.js:*/**/index.js - this selects all bundles that matches translation-*.js and all the files by all paths that name is index.js. : is separator and required only when bundle search used.
    • Format for this kind of filter is BUNDLE_GLOB:FILE_GLOB
  • Filter bundle in one string
    • This is special case of bundle+file filter, you need to omit FILE_GLOB part (empty string)
  • Filter file in one string
    • This is DEFAULT search option
    • */**/index.js - select all files that name is index.js

CLI

This plugin provides cli util rollup-plugin-visualizer. Add --help to check actual options. It can be used like:

rollup-plugin-visualizer [OPTIONS] stat1.json stat2.json ../stat3.json

This can be usefull in case you have different config files in the same project and you want to display all of them in the same chart.

Build plugin

For development if you need to build plugin, just exec:

npm run build

Disclaimer about generated files

Generated html files do not and never will contain your source code (contents of files). They can contain only js/html/css code required to build chart (plugin code) and statistical information about your source code.

This statistical information can contain:

  • size of files included in bundle
  • size of files included in source map
  • file's paths
  • files hierarchy (fs tree for your files)

Upgrades

See CHANGELOG.md.

Versioning

  • Plugin backend (one appears in configs) are strictly follows SemVer
  • Plugin frontend (generated file):
    • network, treemap, sunburst can change does not matter of version (colors, texts, visual structure etc)
    • raw-data format follows own version property
    • list follows semver

版本与发布记录

@aklinker1/rollup-plugin-visualizer 共发布 1 个版本,首次发布于 2024/02/24;过去 12 个月发布了 0 个版本。

版本发布日期距今
5.12.0latest2024/02/242 年前

关于 @aklinker1/rollup-plugin-visualizer 的常见问题

@aklinker1/rollup-plugin-visualizer 是什么?

[](https://github.com/btd

如何安装 @aklinker1/rollup-plugin-visualizer?

在项目目录运行 npm install @aklinker1/rollup-plugin-visualizer,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 rollup-plugin-visualizer,可以用 npx rollup-plugin-visualizer 直接运行。

@aklinker1/rollup-plugin-visualizer 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aklinker1/rollup-plugin-visualizer 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@aklinker1/rollup-plugin-visualizer 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=14。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@aklinker1/rollup-plugin-visualizer 可以商用吗?

@aklinker1/rollup-plugin-visualizer 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@aklinker1/rollup-plugin-visualizer 的下载量有多少?

根据 npm 官方下载统计,@aklinker1/rollup-plugin-visualizer 在 2026/10/06 – 2026/11/04 这 30 天内被下载 2,980,464 次,日均约 99,349 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aklinker1/rollup-plugin-visualizer 还在维护吗?

最新版本 5.12.0 发布于 2024/02/24(2 年前);至今共发布 1 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/02/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。