vite-bundle-explorer 0.1.1
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/LICENSE +21 -0
- package/README.md +54 -0
- package/bin/index.js +32 -0
- package/dist/assets/index-BajBbEJD.css +1 -0
- package/dist/assets/index-CBo5B8y_.js +63 -0
- package/dist/index.html +13 -0
- package/package.json +68 -0
- package/plugin/stats-plugin.js +81 -0
package/dist/index.html
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>vite-bundle-explorer</title>
|
|
7
|
+
<script type="module" crossorigin src="/assets/index-CBo5B8y_.js"></script>
|
|
8
|
+
<link rel="stylesheet" crossorigin href="/assets/index-BajBbEJD.css">
|
|
9
|
+
</head>
|
|
10
|
+
<body>
|
|
11
|
+
<div id="app"></div>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vite-bundle-explorer",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"homepage": "https://github.com/Solant/vite-bundle-explorer#readme",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/Solant/vite-bundle-explorer.git"
|
|
9
|
+
},
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/Solant/vite-bundle-explorer/issues"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"vite",
|
|
15
|
+
"bundle",
|
|
16
|
+
"explorer",
|
|
17
|
+
"analyzer",
|
|
18
|
+
"visualizer",
|
|
19
|
+
"plugin",
|
|
20
|
+
"size",
|
|
21
|
+
"analysis",
|
|
22
|
+
"optimization",
|
|
23
|
+
"stats",
|
|
24
|
+
"visualization",
|
|
25
|
+
"import-graph",
|
|
26
|
+
"dependency-graph",
|
|
27
|
+
"treemap",
|
|
28
|
+
"rollup",
|
|
29
|
+
"performance",
|
|
30
|
+
"build"
|
|
31
|
+
],
|
|
32
|
+
"exports": {
|
|
33
|
+
"./plugin": "./plugin/stats-plugin.js"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"./dist/index.html",
|
|
37
|
+
"./dist/assets",
|
|
38
|
+
"plugin/stats-plugin.js",
|
|
39
|
+
"bin/index.js"
|
|
40
|
+
],
|
|
41
|
+
"bin": {
|
|
42
|
+
"vite-bundle-explorer": "./bin/index.js"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@iconify-json/mdi": "^1.2.3",
|
|
46
|
+
"@types/node": "^24.0.13",
|
|
47
|
+
"@unocss/preset-icons": "^66.3.3",
|
|
48
|
+
"@unocss/preset-wind3": "^66.3.3",
|
|
49
|
+
"@unocss/reset": "^66.3.3",
|
|
50
|
+
"@vitejs/plugin-vue": "^6.0.0",
|
|
51
|
+
"@vue/tsconfig": "^0.7.0",
|
|
52
|
+
"changelogen": "^0.6.2",
|
|
53
|
+
"echarts": "^5.6.0",
|
|
54
|
+
"prettier": "^3.6.2",
|
|
55
|
+
"reka-ui": "^2.3.2",
|
|
56
|
+
"typescript": "~5.8.3",
|
|
57
|
+
"unocss": "^66.3.3",
|
|
58
|
+
"vite": "^7.0.4",
|
|
59
|
+
"vue": "^3.5.17",
|
|
60
|
+
"vue-tsc": "^2.2.12"
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"dev": "vite",
|
|
64
|
+
"build": "vue-tsc -b && vite build && pnpm build:plugin",
|
|
65
|
+
"build:plugin": "tsc --module Node16 --moduleResolution node16 plugin/stats-plugin.ts",
|
|
66
|
+
"release": "pnpm build && pnpm changelogen --release --push && pnpm publish"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { writeFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
function upsertNodeIndex(nodes, item) {
|
|
4
|
+
const index = nodes.indexOf(item);
|
|
5
|
+
return index === -1 ? nodes.push(item) - 1 : index;
|
|
6
|
+
}
|
|
7
|
+
export function statsPlugin() {
|
|
8
|
+
let root = '';
|
|
9
|
+
let outDir = '';
|
|
10
|
+
let enabled = true;
|
|
11
|
+
function truncatePath(filePath) {
|
|
12
|
+
let index = 0;
|
|
13
|
+
const normalizedPath = filePath.replaceAll('\u0000', '');
|
|
14
|
+
if (normalizedPath.startsWith(outDir)) {
|
|
15
|
+
index = outDir.length;
|
|
16
|
+
}
|
|
17
|
+
else if (normalizedPath.startsWith(root)) {
|
|
18
|
+
index = root.length;
|
|
19
|
+
}
|
|
20
|
+
return index > 0 ? normalizedPath.substring(index + 1) : normalizedPath;
|
|
21
|
+
}
|
|
22
|
+
const stats = { chunks: [], importGraph: { nodes: [], edges: [] } };
|
|
23
|
+
const plugin = {
|
|
24
|
+
name: 'stats-plugin',
|
|
25
|
+
configResolved(config) {
|
|
26
|
+
root = config.root;
|
|
27
|
+
outDir = `${root}/${config.build.outDir}`;
|
|
28
|
+
enabled = config.env.PROD;
|
|
29
|
+
},
|
|
30
|
+
resolveId: {
|
|
31
|
+
order: 'pre',
|
|
32
|
+
async handler(source, importer, options) {
|
|
33
|
+
if (!enabled) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
// skip bundle root element
|
|
37
|
+
if (!importer) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const result = await this.resolve(source, importer, { ...options, skipSelf: true });
|
|
41
|
+
if (!result) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const parent = upsertNodeIndex(stats.importGraph.nodes, truncatePath(importer));
|
|
45
|
+
const child = upsertNodeIndex(stats.importGraph.nodes, truncatePath(result.id));
|
|
46
|
+
stats.importGraph.edges.push([parent, child]);
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
generateBundle: {
|
|
50
|
+
async handler(_options, bundle) {
|
|
51
|
+
if (!enabled) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
for (const [_name, chunk] of Object.entries(bundle)) {
|
|
55
|
+
if (chunk.type !== 'chunk') {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const currentChunk = { fileName: chunk.fileName, modules: [] };
|
|
59
|
+
stats.chunks.push(currentChunk);
|
|
60
|
+
for (const [moduleName, mod] of Object.entries(chunk.modules)) {
|
|
61
|
+
const fileName = truncatePath(moduleName);
|
|
62
|
+
currentChunk.modules.push({
|
|
63
|
+
fileName,
|
|
64
|
+
renderedLength: mod.renderedLength,
|
|
65
|
+
virtual: moduleName.startsWith('\u0000') ? true : undefined,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
await writeFile(join(outDir, 'stats.json'), JSON.stringify(stats));
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
closeBundle(error) {
|
|
73
|
+
if (!enabled || error) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
console.log(`Bundle stats written to ${join(outDir, 'stats.json')}`);
|
|
77
|
+
console.log(`Run "npx vite-bundle-explorer ${join(outDir, 'stats.json')}" to view the stats`);
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
return plugin;
|
|
81
|
+
}
|