@@ -6,6 +6,7 @@ import { fileURLToPath } from 'url';
66import { createRequire } from 'module' ;
77import { merge } from 'webpack-merge' ;
88import ReactRefreshPlugin from '@rspack/plugin-react-refresh' ;
9+ import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin' ;
910import { svgLoader , typescriptLoaderProd , typescriptLoaderDev } from '../../scripts/rspack-common.js' ;
1011
1112const require = createRequire ( import . meta. url ) ;
@@ -54,6 +55,14 @@ const common = ({ mode, variant }) => {
5455 new rspack . EnvironmentPlugin ( {
5556 NODE_ENV : mode ,
5657 } ) ,
58+ process . env . RSDOCTOR &&
59+ new RsdoctorRspackPlugin ( {
60+ mode : process . env . RSDOCTOR === 'brief' ? 'brief' : 'normal' ,
61+ disableClientServer : process . env . RSDOCTOR === 'brief' ,
62+ supports : {
63+ generateTileGraph : true ,
64+ } ,
65+ } ) ,
5766 ] . filter ( Boolean ) ,
5867 output : {
5968 chunkFilename : `[name]_ui_[fullhash:6]_${ packageJSON . version } .js` ,
@@ -179,10 +188,12 @@ const commonForProdBrowser = ({ targets = 'last 2 years', useCoreJs = false } =
179188
180189/**
181190 * Production configuration - builds UMD browser variants
182- * @param {'development'|'production' } mode
191+ * @param {object } config
192+ * @param {'development'|'production' } config.mode
193+ * @param {boolean } config.analysis
183194 * @returns {import('@rspack/core').Configuration[] }
184195 */
185- const prodConfig = mode => {
196+ const prodConfig = ( { mode, analysis } ) => {
186197 // Browser bundle with chunks (UMD)
187198 const uiBrowser = merge (
188199 entryForVariant ( variants . uiBrowser ) ,
@@ -197,6 +208,11 @@ const prodConfig = mode => {
197208 commonForProdBrowser ( { targets : packageJSON . browserslistLegacy , useCoreJs : true } ) ,
198209 ) ;
199210
211+ // webpack-bundle-analyzer only supports a single build, use uiBrowser as that's the default build we serve
212+ if ( analysis ) {
213+ return [ uiBrowser ] ;
214+ }
215+
200216 return [ uiBrowser , uiLegacyBrowser ] ;
201217} ;
202218
@@ -247,5 +263,6 @@ const devConfig = (mode, env) => {
247263
248264export default env => {
249265 const mode = env . production ? 'production' : 'development' ;
250- return isProduction ( mode ) ? prodConfig ( mode ) : devConfig ( mode , env ) ;
266+ const analysis = ! ! env . analyze ;
267+ return isProduction ( mode ) ? prodConfig ( { mode, analysis } ) : devConfig ( mode , env ) ;
251268} ;
0 commit comments