24

We developed an app in vite and I want to analyze the bundle of app, I found rollup-plugin-analyzer but it did not work for me.

Pouryak
  • 387
  • 1
  • 3
  • 8

2 Answers2

25

You can use rollup-plugin-visualizer;

import { visualizer } from "rollup-plugin-visualizer";
...
export default defineConfig({
  ...
  plugins: [
    ...
    visualizer({
      template: "treemap", // or sunburst
      open: true,
      gzipSize: true,
      brotliSize: true,
      filename: "analyse.html", // will be saved in project's root
    }) as PluginOption,
    ...
  ],
  ...
});
blek__
  • 98
  • 1
  • 7
DominicSeel
  • 322
  • 4
  • 10
22

Alternatively, you can use vite-bundle-visualizer, which uses rollup-plugin-visualizer:

npx vite-bundle-visualizer

Usage

# In your vite project's root
$ npx vite-bundle-visualizer
# Then open stats.html in browser
$ npx vite-bundle-visualizer --help

vite-bundle-visualizer

Usage:
  $ vite-bundle-visualizer <command> [options]

Options:
  --template -t <template>  Template to use, options are "raw-data" (JSON), "treemap", "list" (YAML), "sunburst" and "network" (default: treemap)
  --output -o <filepath>    Output file path, should be "**/*.html" or "**/*.json" (default: /Users/kuss/project/sides/oss/vite-bundle-visualizer/stats.html)
  --open <open>             Should open browser after generated, except when template is "json" (default: true)
  -h, --help                Display this message

Screenshots

Visualizer Templates

Treemap

$ npx vite-bundle-visualizer

treemap

Sunburst

$ npx vite-bundle-visualizer -t sunburst

sunburst

Network

$ npx vite-bundle-visualizer -t network

network

Raw data

Output raw data (JSON) of stats

# @deprecated vite-bundle-visualizer -t json
$ npx vite-bundle-visualizer -t raw-data

demo/stats.json

Moshe Katz
  • 15,992
  • 7
  • 69
  • 116
tony19
  • 125,647
  • 18
  • 229
  • 307