Skip to content

Commit 6031c15

Browse files
amir-zahediclaude
andauthored
feat(gdu): add bundle analyser for Vite builds (#415)
* 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> * chore: Removes treat --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2e1ed67 commit 6031c15

File tree

7 files changed

+41
-243
lines changed

7 files changed

+41
-243
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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,31 @@ 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(guruConfig.outputPath, 'bundle-report.html'),
107+
open: false,
108+
gzipSize: true,
109+
brotliSize: true,
110+
template: 'treemap',
111+
}),
112+
);
113+
} catch {
114+
console.warn(
115+
magenta(
116+
'Warning: rollup-plugin-visualizer is not installed. ' +
117+
'Install it to enable bundle analysis for Vite builds: ' +
118+
'yarn add -D rollup-plugin-visualizer',
119+
),
120+
);
121+
}
122+
}
123+
99124
const { build } = (await dynamicImport('vite')) as {
100125
build: (config: InlineConfig) => Promise<unknown>;
101126
};

packages/gdu/config/webpack/webpack.config.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import envCI from 'env-ci';
88
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
99
import { MinifyOptions } from 'terser';
1010
import TerserPlugin, { MinimizerOptions } from 'terser-webpack-plugin';
11-
import { TreatPlugin } from 'treat/webpack-plugin';
1211
import { TsconfigPathsPlugin } from 'tsconfig-paths-webpack-plugin';
1312
import {
1413
Configuration,
@@ -23,7 +22,6 @@ import {
2322
getProjectFolderName,
2423
getProjectName,
2524
} from '../../lib/config';
26-
import { isProductionBuild } from '../../lib/misc';
2725
import {
2826
CALLING_WORKSPACE_ROOT,
2927
GDU_ROOT,
@@ -388,17 +386,6 @@ export const baseOptions = ({
388386
branch,
389387
}),
390388
}),
391-
new TreatPlugin({
392-
outputLoaders: [
393-
{
394-
loader: isProductionBuild()
395-
? MiniCssExtractPlugin.loader
396-
: require.resolve('style-loader'),
397-
},
398-
],
399-
minify: true,
400-
browsers,
401-
}),
402389
new VanillaExtractPlugin(),
403390
new MiniCssExtractPlugin({
404391
filename: `${fileMask}.css`,

packages/gdu/config/webpack/webpack.development.config.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import browsers from 'browserslist-config-autoguru';
55
import Dotenv from 'dotenv-webpack';
66
import envCI from 'env-ci';
77
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
8-
import { TreatPlugin } from 'treat/webpack-plugin';
98
import { TsconfigPathsPlugin } from 'tsconfig-paths-webpack-plugin';
109
import {
1110
Configuration,
@@ -354,15 +353,6 @@ export const baseDevelopmentOptions = ({
354353
branch,
355354
}),
356355
}),
357-
new TreatPlugin({
358-
outputLoaders: [
359-
{
360-
loader: require.resolve('style-loader'),
361-
},
362-
],
363-
minify: false,
364-
browsers,
365-
}),
366356
new VanillaExtractPlugin(),
367357
new MiniCssExtractPlugin({
368358
filename: `${fileMask}.css`,

packages/gdu/config/webpack/webpack.webcomponents.config.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import envCI from 'env-ci';
88
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
99
import { MinifyOptions } from 'terser';
1010
import TerserPlugin, { MinimizerOptions } from 'terser-webpack-plugin';
11-
import { TreatPlugin } from 'treat/webpack-plugin';
1211
import { TsconfigPathsPlugin } from 'tsconfig-paths-webpack-plugin';
1312
import {
1413
Configuration,
@@ -18,7 +17,6 @@ import {
1817
} from 'webpack';
1918

2019
import { getGuruConfig, getProjectName } from '../../lib/config';
21-
import { isProductionBuild } from '../../lib/misc';
2220
import { CALLING_WORKSPACE_ROOT, PROJECT_ROOT } from '../../lib/roots';
2321
import { getHooks } from '../../utils/hooks';
2422

@@ -305,17 +303,6 @@ export const makeWebComponentsWebpackConfig = (
305303
branch,
306304
}),
307305
}),
308-
new TreatPlugin({
309-
outputLoaders: [
310-
{
311-
loader: isProductionBuild()
312-
? MiniCssExtractPlugin.loader
313-
: require.resolve('style-loader'),
314-
},
315-
],
316-
minify: !isDev,
317-
browsers,
318-
}),
319306
new VanillaExtractPlugin(),
320307
new MiniCssExtractPlugin({
321308
filename: `${fileMask}.css`,

packages/gdu/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
"sade": "^1.7.4",
8484
"tapable": "^2.2.0",
8585
"terser-webpack-plugin": "^5.3.11",
86-
"treat": "2.0.4",
8786
"ts-dedent": "^2.2.0",
8887
"tsconfig-paths-webpack-plugin": "^3.5.2",
8988
"url-loader": "^4.1.1",

0 commit comments

Comments
 (0)