Skip to content

Commit 9663907

Browse files
committed
Update readme
1 parent ae27042 commit 9663907

1 file changed

Lines changed: 87 additions & 83 deletions

File tree

README.md

Lines changed: 87 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![NPM Version](https://img.shields.io/npm/v/rollup-plugin-visualizer.svg)](https://npmjs.org/package/rollup-plugin-visualizer) [![Node.js CI](https://github.com/btd/rollup-plugin-visualizer/actions/workflows/node.js.yml/badge.svg)](https://github.com/btd/rollup-plugin-visualizer/actions/workflows/node.js.yml)
44

5-
Visualize and analyze your Rollup bundle to see which modules are taking up space.
5+
Visualize and analyze your bundle to quickly see which modules are taking up space.
66

77
## Screenshots
88

@@ -20,44 +20,49 @@ or via yarn:
2020
yarn add --dev rollup-plugin-visualizer
2121
```
2222

23-
## Usage
24-
2523
## Requirements
2624

27-
This package is **ESM-only** and requires Node.js >= 22.
25+
This package requires Node.js >= 22.
26+
27+
## Usage
2828

29-
Import
29+
Import the plugin:
3030

3131
```javascript
3232
import { visualizer } from "rollup-plugin-visualizer";
3333
```
3434

35-
Usage with rollup (rollup.config.js)
35+
Or in CommonJS:
36+
37+
```js
38+
const { visualizer } = require("rollup-plugin-visualizer");
39+
```
40+
41+
### Rollup (`rollup.config.js`)
3642

3743
```js
3844
import { visualizer } from "rollup-plugin-visualizer";
3945

4046
export default {
4147
plugins: [
42-
// put it last
48+
// Keep it last.
4349
visualizer(),
4450
],
4551
};
4652
```
4753

48-
Usage with rolldown (rolldown.config.ts)
54+
### Rolldown (`rolldown.config.ts`)
4955

5056
```js
51-
import { defineConfig, type RolldownPlugin } from 'rolldown';
57+
import { defineConfig, type RolldownPlugin } from "rolldown";
58+
import { visualizer } from "rollup-plugin-visualizer";
5259

5360
export default defineConfig({
54-
plugins: [
55-
visualizer() as RolldownPlugin
56-
],
57-
})
61+
plugins: [visualizer() as RolldownPlugin],
62+
});
5863
```
5964

60-
Usage with vite (vite.config.js)
65+
### Vite (`vite.config.js`)
6166

6267
```js
6368
import { visualizer } from "rollup-plugin-visualizer";
@@ -67,17 +72,18 @@ export default {
6772
};
6873
```
6974

70-
Usage with vite TypeScript (vite.config.ts)
75+
### Vite + TypeScript (`vite.config.ts`)
7176

7277
```ts
7378
import { defineConfig, type PluginOption } from "vite";
79+
import { visualizer } from "rollup-plugin-visualizer";
7480

7581
export default defineConfig({
7682
plugins: [visualizer() as PluginOption],
7783
});
7884
```
7985

80-
Usage with SvelteKit (vite.config.js)
86+
### SvelteKit (`vite.config.js`)
8187

8288
```js
8389
import { visualizer } from "rollup-plugin-visualizer";
@@ -92,131 +98,129 @@ export default {
9298
};
9399
```
94100

95-
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.
96-
You can also generate 3 json files and combine them to one with cli util.
97-
98-
## How to use generated files
99-
100-
Blue color used to to mark project-own files. This could be: written by you files or generated by build tool files.
101+
SvelteKit may run Vite multiple times, so you can get 2-3 generated files in `.svelte-kit/output` (check Vite logs for exact locations).
102+
You can also generate raw JSON reports and merge them with the CLI.
101103

102-
Green color used to mark your dependencies.
104+
## Understanding The Report
103105

104-
Internally it just checks if file id prefix is `node_modules`.
105-
106-
All charts refresh layout on window resize.
106+
- Blue marks project files (including files generated by your build tool).
107+
- Green marks dependencies.
108+
- This is determined by whether a file path starts with `node_modules`.
109+
- All chart layouts refresh when the window is resized.
107110

108111
### Sunburst
109112

110-
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.
113+
The circular view is useful for spotting large chunks of code. Clicking an arc zooms into that section and enlarges nested arcs for inspection.
111114

112115
### Flamegraph
113116

114-
This diagram is top down version of sunburst. It is used a lot by other JS developer tools and would be very familar to developers.
117+
This is a top-down version of the sunburst view and should feel familiar if you use other JavaScript performance tooling.
115118

116119
### Treemap
117120

118-
This rectangular hierarchical diagram can help you find huge pieces. Just look on biggest rectangle. But also it can help you find modules included several times, they will have the same topology and relative size. If you click on rectangle it will increase in size for further inspection.
121+
This rectangular hierarchical view makes large modules easy to find quickly. It can also reveal repeated modules, because repeated content tends to show similar structure and relative size.
119122

120123
### Network
121124

122-
This diagram 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 treeshaken out files.
125+
Use this view to answer, "Why is this included?"
126+
After the force layout stabilizes, you can drag nodes around. Gray circles are tree-shaken files.
127+
128+
In real projects, network graphs can look noisy. A practical way to explore them is:
123129

124-
In real life scenarios, 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 inspectable, 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.
130+
1. Remove highly connected helper nodes (for example `commonjsHelpers`, `tslib`, `react`) when they dominate the graph.
131+
2. Wait for layout stabilization.
132+
3. Explore clusters that become easier to read.
125133

126-
When you click on node it will highlight nodes that are listed in tooltip (the files that imports current node).
134+
Clicking a node highlights nodes listed in its tooltip (the files that import that node).
127135

128136
### Raw-data
129137

130-
This template produce JSON output with raw data. Normally it should be used with CLI from this plugin.
138+
Produces JSON output with raw data. Usually used together with the CLI.
131139

132140
### List
133141

134-
Output yml file with all the data, could be good idea to commit this file to track file changes.
142+
Produces a YAML file with report data. This is useful to commit and track bundle changes over time.
135143

136144
### Markdown
137145

138-
Output markdown report with summary tables and bottom notes about report config and size precision.
146+
Produces a Markdown report with summary tables and notes about config and size precision.
139147

140148
## Options
141149

142-
`filename` (string, default `stats.{ext depending template}`) - name of the file with diagram to generate
143-
144-
`title` (string, default `Rollup Visualizer`) - title tag value
145-
146-
`open` (boolean, default `false`) - Open generated file in default user agent
147-
148-
`template` (string, default `treemap`) - Which diagram type to use: `sunburst`, `treemap`, `network`, `raw-data`, `list`, `markdown`, `flamegraph`.
149-
150-
`gzipSize` (boolean, default `false`) - Collect gzip size from source code and display it at chart.
151-
152-
`brotliSize` (boolean, default `false`) - Collect brotli size from source code and display it at chart.
150+
- `filename` (`string`, default `stats.{ext based on template}`): Name of the generated report file.
151+
- `title` (`string`, default `Rollup Visualizer`): HTML `<title>` value.
152+
- `open` (`boolean`, default `false`): Open the generated file in your default browser.
153+
- `template` (`string`, default `treemap`): Report type: `sunburst`, `treemap`, `network`, `raw-data`, `list`, `markdown`, `flamegraph`.
154+
- `gzipSize` (`boolean`, default `false`): Include gzip size in the report.
155+
- `brotliSize` (`boolean`, default `false`): Include Brotli size in the report.
153156

154-
### Advanced options (touch only if you really need it):
157+
### Advanced options (only if needed)
155158

156-
`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 useful with svelte as it calls vite several times.
159+
- `emitFile` (`boolean`, default `false`): Use Rollup `emitFile` to generate output. Useful when you want all assets managed by Rollup output settings. Also helpful for SvelteKit multi-build runs. When this is `true`, `filename` must be a file name, not a path.
160+
- `sourcemap` (`boolean`, default `false`): Use source maps for module size calculations (for example after Terser/UglifyJS). Keep this plugin last.
161+
- `projectRoot` (`string | RegExp`, default `process.cwd()`): Common root path used to trim absolute file paths in reports.
162+
- `include` (`Filter | Filter[]`, default `undefined`): Include filter.
163+
- `exclude` (`Filter | Filter[]`, default `undefined`): Exclude filter.
157164

158-
`sourcemap` (boolean, default `false`) - Use sourcemaps to calculate sizes (e.g. after UglifyJs or Terser). **Always add plugin as last option.**
165+
`Filter` type: `{ bundle?: picomatchPattern, file?: picomatchPattern }`
159166

160-
`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.
167+
**Note on `include` and `exclude`**:
168+
If `include` is omitted or empty, files are included by default.
169+
Otherwise, an ID must match at least one `include` pattern and must not match any `exclude` pattern.
161170

162-
`include` (Filter | Filter[], default `undefined`) - Filter for inclusion
171+
### Include And Exclude
163172

164-
`exclude` (Filter | Filter[], default `undefined`) - Filter for exclusion
173+
Filters use picomatch globs, and support these forms:
165174

166-
`Filter` type is `{ bundle?: picomatchPattern, file?: picomatchPattern }`
175+
- Bundle + file in one string: `translation-*.js:*/**/index.js`
176+
- Bundle only: `translation-*.js:`
177+
- File only (default): `*/**/index.js`
167178

168-
**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.
169-
170-
#### Include and Exclude
171-
172-
Include and exclude filters uses glob matchers with picomatch. In UI you can do such combinations (both exclude and include):
173-
174-
- Filter bundle and file in one string
175-
- `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.
176-
- Format for this kind of filter is `BUNDLE_GLOB:FILE_GLOB`
177-
- Filter bundle in one string
178-
- This is special case of bundle+file filter, you need to omit `FILE_GLOB` part (empty string)
179-
- Filter file in one string
180-
- **This is DEFAULT search option**
181-
- `*/**/index.js` - select all files that name is index.js
179+
Format: `BUNDLE_GLOB:FILE_GLOB` (`:` is required when bundle matching is used).
182180

183181
## CLI
184182

185-
This plugin provides cli util `rollup-plugin-visualizer`. Add `--help` to check actual options. It can be used like:
183+
This package provides a CLI utility: `rollup-plugin-visualizer`.
184+
185+
Use `--help` to see all available options:
186186

187187
```sh
188188
rollup-plugin-visualizer [OPTIONS] stat1.json stat2.json ../stat3.json
189189
```
190190

191-
This can be useful in case you have different config files in the same project and you want to display all of them in the same chart.
191+
This is useful when you have multiple build configs and want to combine reports into one chart.
192192

193193
## Build plugin
194194

195-
For development if you need to build plugin, just exec:
195+
For local development:
196196

197-
```js
197+
```sh
198198
npm run build
199199
```
200200

201201
## Disclaimer about generated files
202202

203-
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.
203+
Generated HTML files do not include your source code contents.
204+
They only include:
205+
206+
- JS/HTML/CSS required for the chart UI
207+
- Statistical metadata about your code
204208

205-
This statistical information can contain:
209+
This metadata can include:
206210

207-
- size of files included in bundle
208-
- size of files included in source map
209-
- file's paths
210-
- files hierarchy (fs tree for your files)
211+
- Sizes of files in the bundle
212+
- Sizes of files in source maps
213+
- File paths
214+
- File hierarchy
211215

212216
## Upgrades
213217

214-
See CHANGELOG.md.
218+
See `CHANGELOG.md`.
215219

216220
## Versioning
217221

218-
- Plugin backend (one appears in configs) are strictly follows SemVer
219-
- Plugin frontend (generated file):
220-
- `network`, `treemap`, `sunburst`, `flamegraph` can change does not matter of version (colors, texts, visual structure etc)
221-
- `raw-data` format follows own `version` property
222-
- `list` and `markdown` follows semver
222+
- The plugin API (the part used in your build config) follows SemVer.
223+
- Frontend report templates can change visual details (`network`, `treemap`, `sunburst`, `flamegraph`) without strict SemVer guarantees.
224+
- `raw-data` uses its own `version` field.
225+
- `list` output follows SemVer.
226+
- `markdown` output is experimental and does not follow strict versioning. It will evolve with LLM capabilities.

0 commit comments

Comments
 (0)