Skip to content

Commit 8775339

Browse files
Merge pull request #512 from core-ds/fix/run-bundle-analyze
fix run bundle-analyze
2 parents 4756122 + e2b0ee1 commit 8775339

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

.changeset/angry-donuts-act.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'arui-scripts': patch
3+
---
4+
5+
Исправлен запуск команды `bundle-analyze`. Теперь явно включаются необходимые поля stats для `webpack-bundle-analyzer`, которые больше не попадают в `stats.toJson()` по умолчанию

packages/arui-scripts/src/commands/bundle-analyze/index.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,37 @@
11
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
2-
import { rspack, type WebpackPluginInstance } from '@rspack/core';
2+
import {
3+
rspack,
4+
type RspackOptionsNormalized,
5+
type WebpackPluginInstance,
6+
} from '@rspack/core';
37
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
48

59
import { configs } from '../../configs/app-configs';
610
import { webpackClientConfig } from '../../configs/webpack.client.prod';
711
import { makeTmpDir } from '../util/make-tmp-dir';
812

13+
type BundleAnalyzerStatsOptions = {
14+
assets: boolean;
15+
chunks: boolean;
16+
chunkGroups: boolean;
17+
chunkModules: boolean;
18+
entryPoints: boolean;
19+
entrypoints: boolean;
20+
modules: boolean;
21+
};
22+
23+
// В rspack по умолчанию больше не включаются эти поля, но для webpack-bundle-analyzer они нужны
24+
// https://rspack.rs/guide/migration/rspack_1.x#changed-default-parameters-of-statstojson
25+
const bundleAnalyzerStatsOptions: BundleAnalyzerStatsOptions = {
26+
assets: true,
27+
chunks: true,
28+
chunkGroups: true,
29+
chunkModules: true,
30+
entryPoints: true,
31+
entrypoints: true,
32+
modules: true,
33+
};
34+
935
(async () => {
1036
console.log('Starting bundle analysis...');
1137

@@ -16,19 +42,25 @@ import { makeTmpDir } from '../util/make-tmp-dir';
1642
/* eslint-disable no-param-reassign */
1743
const promises = clientWebpackConfigs.map(async (webpackConfig, i) => {
1844
const tmpDir = await makeTmpDir(i.toString());
45+
const webpackStatsOptions: RspackOptionsNormalized['stats'] = {
46+
...(typeof webpackConfig.stats === 'object' ? webpackConfig.stats : {}),
47+
...bundleAnalyzerStatsOptions,
48+
};
1949

2050
webpackConfig.plugins = [
2151
...(webpackConfig.plugins || []),
2252
new BundleAnalyzerPlugin({
2353
generateStatsFile: true,
2454
statsFilename: configs.statsOutputPath,
55+
statsOptions: bundleAnalyzerStatsOptions,
2556
analyzerPort: 'auto',
2657
analyzerMode: 'server',
2758
openAnalyzer: true,
2859
logLevel: 'info',
2960
}) as unknown as WebpackPluginInstance, // webpack-bundle-analyzer has incorrect types
3061
new RsdoctorRspackPlugin({}),
3162
];
63+
webpackConfig.stats = webpackStatsOptions;
3264
webpackConfig.output = {
3365
...webpackConfig.output,
3466
path: tmpDir,

0 commit comments

Comments
 (0)