-
Notifications
You must be signed in to change notification settings - Fork 0
feat(gdu): add bundle analyser for Vite builds #415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "gdu": minor | ||
| --- | ||
|
|
||
| Add bundle analyser support for Vite builds via `gdu build -a` flag |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -96,6 +96,31 @@ export const buildSPAVite = async (guruConfig: GuruConfig) => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (process.env.ANALYZE === 'true') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { visualizer } = await dynamicImport( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'rollup-plugin-visualizer', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| runtimePlugins.push( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| visualizer({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| filename: join(guruConfig.outputPath, 'bundle-report.html'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| open: false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| gzipSize: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| brotliSize: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| template: 'treemap', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.warn( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| magenta( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'Warning: rollup-plugin-visualizer is not installed. ' + | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'Install it to enable bundle analysis for Vite builds: ' + | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'yarn add -D rollup-plugin-visualizer', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+113
to
+120
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch { | |
| console.warn( | |
| magenta( | |
| 'Warning: rollup-plugin-visualizer is not installed. ' + | |
| 'Install it to enable bundle analysis for Vite builds: ' + | |
| 'yarn add -D rollup-plugin-visualizer', | |
| ), | |
| ); | |
| } catch (error) { | |
| const err = error as { code?: unknown; message?: unknown }; | |
| const errorCode = typeof err.code === 'string' ? err.code : undefined; | |
| const isModuleNotFound = | |
| errorCode === 'MODULE_NOT_FOUND' || | |
| errorCode === 'ERR_MODULE_NOT_FOUND'; | |
| if (isModuleNotFound) { | |
| console.warn( | |
| magenta( | |
| 'Warning: rollup-plugin-visualizer is not installed. ' + | |
| 'Install it to enable bundle analysis for Vite builds: ' + | |
| 'yarn add -D rollup-plugin-visualizer', | |
| ), | |
| ); | |
| } else { | |
| const errorMessage = | |
| typeof err.message === 'string' | |
| ? err.message | |
| : String(error); | |
| console.warn( | |
| magenta( | |
| 'Warning: Failed to load rollup-plugin-visualizer for bundle analysis. ' + | |
| `Error: ${errorMessage}`, | |
| ), | |
| ); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In production multi-env builds, Vite’s
outDiris computed per config (e.g.${guruConfig.outputPath}/${buildEnv}), but the visualizer report is always written tojoin(guruConfig.outputPath, 'bundle-report.html'). SincebuildSPAViteloops over multiple configs, this will overwrite the same report file and place it outside the per-env output directory. Consider constructing the report filename from the current config’sbuild.outDir(or otherwise making it env-specific) and adding the visualizer plugin per-config inside the loop.