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 +12 -12
- package/package.json +1 -1
- package/plugin/stats-plugin.d.ts +1 -0
- package/plugin/stats-plugin.js +10 -10
package/README.md
CHANGED
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Bundle analyzer and visualizer tool for vite.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
- Chunk
|
|
8
|
-
- Module import graph
|
|
9
|
-
-
|
|
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
|

|
|
13
12
|
|
|
@@ -63,9 +62,10 @@ export default defineConfig({
|
|
|
63
62
|
});
|
|
64
63
|
```
|
|
65
64
|
|
|
66
|
-
| Parameter | Type | Default
|
|
67
|
-
|
|
68
|
-
| `
|
|
69
|
-
| `
|
|
70
|
-
| `
|
|
71
|
-
| `
|
|
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
package/plugin/stats-plugin.d.ts
CHANGED
package/plugin/stats-plugin.js
CHANGED
|
@@ -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 =
|
|
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
|
-
|
|
35
|
-
|
|
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 {
|