Skip to content

Commit d808f7d

Browse files
committed
fix: prevent error when closeBundle is executed twice, update documentation
1 parent 97d7034 commit d808f7d

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
Bundle analyzer and visualizer tool for vite.
44

5-
Current features:
6-
7-
- Chunk size treemap
8-
- Module import graph
9-
- Build stats report
10-
- Detect duplicated dependencies
5+
- ✅ Supports both applications and libraries
6+
- ✅ Supports `vite`, `rollup`, `rolldown` and `tsdown`
7+
- ✅ Chunk treemap
8+
- ✅ Module import graph
9+
- ✅ Detect duplicated dependencies
1110

1211
![preview](https://raw.githubusercontent.com/Solant/vite-bundle-explorer/refs/heads/main/preview.gif)
1312

@@ -63,9 +62,10 @@ export default defineConfig({
6362
});
6463
```
6564

66-
| Parameter | Type | Default | Description |
67-
|------------------------|-----------|--------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------|
68-
| `reportCompressedSize` | `boolean` | Same as Vite's [build.reportCompressedSize](https://vite.dev/config/build-options.html#build-reportcompressedsize) | Calculate compressed size of chunks. Might affect performance. |
69-
| `reportDirectoryName` | `string` | `"bundle-report"` | Name of the output directory |
70-
| `emitHtml` | `boolean` | `true` | Generate interactive HTML report |
71-
| `emitJson` | `boolean` | `false` | Generate `stats.json` file |
65+
| Parameter | Type | Default | Description |
66+
|------------------------|-----------|-------------------|------------------------------------------------------------------------------------------------------------|
67+
| `enabled` | `boolean` | `true` | Disables stats collection and report generation. This option is disabled automatically for `vite dev` mode |
68+
| `reportCompressedSize` | `boolean` | `true` | Calculate compressed size of chunks. Might affect performance. |
69+
| `reportDirectoryName` | `string` | `"bundle-report"` | Name of the output directory |
70+
| `emitHtml` | `boolean` | `true` | Generate interactive HTML report |
71+
| `emitJson` | `boolean` | `false` | Generate `stats.json` file |

plugin/stats-plugin.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { type Plugin } from 'vite';
22

33
interface StatsPluginOptions {
4+
enabled?: boolean;
45
reportDirectoryName?: string;
56
reportCompressedSize?: boolean;
67
emitHtml?: boolean;

plugin/stats-plugin.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,7 @@ export function statsPlugin(options?: StatsPluginOptions) {
5454
// vite specific hook
5555
configResolved(config) {
5656
// disable during dev mode
57-
enabled = config.env.PROD;
58-
},
59-
outputOptions(opts) {
60-
// workaround for libraries with multiple output formats
61-
enabled = opts.format === 'es';
57+
enabled = enabled && config.env.PROD;
6258
},
6359
resolveId: {
6460
order: 'pre',
@@ -138,6 +134,8 @@ export function statsPlugin(options?: StatsPluginOptions) {
138134
if (!enabled || error) {
139135
return;
140136
}
137+
// prevent this hook from being called again for a different format
138+
enabled = false;
141139

142140
// create a target directory
143141
const target = join(root, options?.reportDirectoryName ?? REPORT_DIR_NAME);

0 commit comments

Comments
 (0)