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.
Asked
Active
Viewed 1.0k times
2 Answers
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
-
+ `[yarn|npm run] build` to generate the output – Pierre de LESPINAY Jun 16 '23 at 12:36
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
Sunburst
$ npx vite-bundle-visualizer -t sunburst
Network
$ npx vite-bundle-visualizer -t network
Raw data
Output raw data (JSON) of stats
# @deprecated vite-bundle-visualizer -t json
$ npx vite-bundle-visualizer -t raw-data

Moshe Katz
- 15,992
- 7
- 69
- 116

tony19
- 125,647
- 18
- 229
- 307