From e2b0ee1d3376e359a7e466de7a5d3c37ed672684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=BE=D1=80=D0=BE=D0=B2=D1=81=D0=BA=D0=B8=D0=B9=20?= =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Mon, 1 Jun 2026 12:18:25 +0300 Subject: [PATCH] fix(*): fix run bundle-analyze --- .changeset/angry-donuts-act.md | 5 +++ .../src/commands/bundle-analyze/index.ts | 34 ++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 .changeset/angry-donuts-act.md diff --git a/.changeset/angry-donuts-act.md b/.changeset/angry-donuts-act.md new file mode 100644 index 00000000..4abd38e3 --- /dev/null +++ b/.changeset/angry-donuts-act.md @@ -0,0 +1,5 @@ +--- +'arui-scripts': patch +--- + +Исправлен запуск команды `bundle-analyze`. Теперь явно включаются необходимые поля stats для `webpack-bundle-analyzer`, которые больше не попадают в `stats.toJson()` по умолчанию diff --git a/packages/arui-scripts/src/commands/bundle-analyze/index.ts b/packages/arui-scripts/src/commands/bundle-analyze/index.ts index 5ab859b3..c0779000 100644 --- a/packages/arui-scripts/src/commands/bundle-analyze/index.ts +++ b/packages/arui-scripts/src/commands/bundle-analyze/index.ts @@ -1,11 +1,37 @@ import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin'; -import { rspack, type WebpackPluginInstance } from '@rspack/core'; +import { + rspack, + type RspackOptionsNormalized, + type WebpackPluginInstance, +} from '@rspack/core'; import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'; import { configs } from '../../configs/app-configs'; import { webpackClientConfig } from '../../configs/webpack.client.prod'; import { makeTmpDir } from '../util/make-tmp-dir'; +type BundleAnalyzerStatsOptions = { + assets: boolean; + chunks: boolean; + chunkGroups: boolean; + chunkModules: boolean; + entryPoints: boolean; + entrypoints: boolean; + modules: boolean; +}; + +// В rspack по умолчанию больше не включаются эти поля, но для webpack-bundle-analyzer они нужны +// https://rspack.rs/guide/migration/rspack_1.x#changed-default-parameters-of-statstojson +const bundleAnalyzerStatsOptions: BundleAnalyzerStatsOptions = { + assets: true, + chunks: true, + chunkGroups: true, + chunkModules: true, + entryPoints: true, + entrypoints: true, + modules: true, +}; + (async () => { console.log('Starting bundle analysis...'); @@ -16,12 +42,17 @@ import { makeTmpDir } from '../util/make-tmp-dir'; /* eslint-disable no-param-reassign */ const promises = clientWebpackConfigs.map(async (webpackConfig, i) => { const tmpDir = await makeTmpDir(i.toString()); + const webpackStatsOptions: RspackOptionsNormalized['stats'] = { + ...(typeof webpackConfig.stats === 'object' ? webpackConfig.stats : {}), + ...bundleAnalyzerStatsOptions, + }; webpackConfig.plugins = [ ...(webpackConfig.plugins || []), new BundleAnalyzerPlugin({ generateStatsFile: true, statsFilename: configs.statsOutputPath, + statsOptions: bundleAnalyzerStatsOptions, analyzerPort: 'auto', analyzerMode: 'server', openAnalyzer: true, @@ -29,6 +60,7 @@ import { makeTmpDir } from '../util/make-tmp-dir'; }) as unknown as WebpackPluginInstance, // webpack-bundle-analyzer has incorrect types new RsdoctorRspackPlugin({}), ]; + webpackConfig.stats = webpackStatsOptions; webpackConfig.output = { ...webpackConfig.output, path: tmpDir,