Skip to content

Commit 535495e

Browse files
amir-zahediclaude
andcommitted
feat(gdu): add bundle analyser support for Vite builds
Enable the existing `gdu build -a` / `ANALYZE=true` flag for Vite builds using rollup-plugin-visualizer. Generates an interactive treemap report at `bundle-report.html` in the output directory, matching the webpack behaviour. The plugin is dynamically imported with a try/catch fallback (consistent with vanilla-extract pattern) so consumers need rollup-plugin-visualizer installed. AG-17604 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2e1ed67 commit 535495e

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

.changeset/vite-bundle-analyser.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gdu": minor
3+
---
4+
5+
Add bundle analyser support for Vite builds via `gdu build -a` flag

packages/gdu/commands/build/buildSPA-vite.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,34 @@ export const buildSPAVite = async (guruConfig: GuruConfig) => {
9696
}),
9797
);
9898

99+
if (process.env.ANALYZE === 'true') {
100+
try {
101+
const { visualizer } = await dynamicImport(
102+
'rollup-plugin-visualizer',
103+
);
104+
runtimePlugins.push(
105+
visualizer({
106+
filename: join(
107+
guruConfig.outputPath,
108+
'bundle-report.html',
109+
),
110+
open: false,
111+
gzipSize: true,
112+
brotliSize: true,
113+
template: 'treemap',
114+
}),
115+
);
116+
} catch {
117+
console.warn(
118+
magenta(
119+
'Warning: rollup-plugin-visualizer is not installed. ' +
120+
'Install it to enable bundle analysis for Vite builds: ' +
121+
'yarn add -D rollup-plugin-visualizer',
122+
),
123+
);
124+
}
125+
}
126+
99127
const { build } = (await dynamicImport('vite')) as {
100128
build: (config: InlineConfig) => Promise<unknown>;
101129
};

0 commit comments

Comments
 (0)