vite-bundle-explorer 0.3.0 → 0.3.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/package.json +1 -1
- package/plugin/stats-plugin.js +11 -9
package/package.json
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,14 @@ 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
|
-
outDir = `${root}/${config.build.outDir}`;
|
|
35
|
+
// disable during dev mode
|
|
36
36
|
enabled = config.env.PROD;
|
|
37
|
-
|
|
37
|
+
},
|
|
38
|
+
outputOptions(opts) {
|
|
39
|
+
// workaround for libraries with multiple output formats
|
|
40
|
+
enabled = opts.format === 'es';
|
|
38
41
|
},
|
|
39
42
|
resolveId: {
|
|
40
43
|
order: 'pre',
|
|
@@ -64,7 +67,6 @@ export function statsPlugin(options) {
|
|
|
64
67
|
if (chunk.type !== 'chunk') {
|
|
65
68
|
continue;
|
|
66
69
|
}
|
|
67
|
-
console.log(`Processing chunk "${chunk.fileName}"`);
|
|
68
70
|
const currentChunk = {
|
|
69
71
|
fileName: chunk.fileName,
|
|
70
72
|
modules: [],
|