vite-bundle-explorer 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,12 +2,11 @@
2
2
 
3
3
  Bundle analyzer and visualizer tool for vite.
4
4
 
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
11
10
 
12
11
  ![preview](https://raw.githubusercontent.com/Solant/vite-bundle-explorer/refs/heads/main/preview.gif)
13
12
 
@@ -63,9 +62,10 @@ export default defineConfig({
63
62
  });
64
63
  ```
65
64
 
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 |
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-bundle-explorer",
3
3
  "description": "Bundle analyzer and visualizer tool for Vite",
4
- "version": "0.3.0",
4
+ "version": "0.3.2",
5
5
  "type": "module",
6
6
  "homepage": "https://github.com/Solant/vite-bundle-explorer#readme",
7
7
  "repository": {
@@ -1,6 +1,7 @@
1
1
  import { type Plugin } from 'vite';
2
2
 
3
3
  interface StatsPluginOptions {
4
+ enabled?: boolean;
4
5
  reportDirectoryName?: string;
5
6
  reportCompressedSize?: boolean;
6
7
  emitHtml?: boolean;
@@ -11,17 +11,17 @@ function upsertNodeIndex(nodes, item) {
11
11
  export function statsPlugin(options) {
12
12
  const emitHtml = options?.emitHtml ?? true;
13
13
  const emitJson = options?.emitJson ?? false;
14
- let root = '';
14
+ let root = process.cwd();
15
15
  let outDir = '';
16
- let enabled = true;
17
- let reportCompressed = false;
16
+ let enabled = options?.enabled ?? true;
17
+ let reportCompressed = true;
18
18
  function truncatePath(filePath) {
19
19
  let index = 0;
20
20
  const normalizedPath = filePath.replaceAll('\u0000', '');
21
- if (normalizedPath.startsWith(outDir)) {
21
+ if (outDir && normalizedPath.startsWith(outDir)) {
22
22
  index = outDir.length;
23
23
  }
24
- else if (normalizedPath.startsWith(root)) {
24
+ else if (root && normalizedPath.startsWith(root)) {
25
25
  index = root.length;
26
26
  }
27
27
  return index > 0 ? normalizedPath.substring(index + 1) : normalizedPath;
@@ -30,11 +30,10 @@ export function statsPlugin(options) {
30
30
  const stats = { chunks: [], importGraph: { edges: [] }, moduleFileNames: [] };
31
31
  const plugin = {
32
32
  name: 'stats-plugin',
33
+ // vite specific hook
33
34
  configResolved(config) {
34
- root = config.root;
35
- outDir = `${root}/${config.build.outDir}`;
36
- enabled = config.env.PROD;
37
- reportCompressed = options?.reportCompressedSize ?? config.build.reportCompressedSize;
35
+ // disable during dev mode
36
+ enabled = enabled && config.env.PROD;
38
37
  },
39
38
  resolveId: {
40
39
  order: 'pre',
@@ -64,7 +63,6 @@ export function statsPlugin(options) {
64
63
  if (chunk.type !== 'chunk') {
65
64
  continue;
66
65
  }
67
- console.log(`Processing chunk "${chunk.fileName}"`);
68
66
  const currentChunk = {
69
67
  fileName: chunk.fileName,
70
68
  modules: [],
@@ -106,6 +104,8 @@ export function statsPlugin(options) {
106
104
  if (!enabled || error) {
107
105
  return;
108
106
  }
107
+ // prevent this hook from being called again for a different format
108
+ enabled = false;
109
109
  // create a target directory
110
110
  const target = join(root, options?.reportDirectoryName ?? REPORT_DIR_NAME);
111
111
  try {