Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/angry-donuts-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'arui-scripts': patch
---

Исправлен запуск команды `bundle-analyze`. Теперь явно включаются необходимые поля stats для `webpack-bundle-analyzer`, которые больше не попадают в `stats.toJson()` по умолчанию
34 changes: 33 additions & 1 deletion packages/arui-scripts/src/commands/bundle-analyze/index.ts
Original file line number Diff line number Diff line change
@@ -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...');

Expand All @@ -16,19 +42,25 @@ 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,
logLevel: 'info',
}) as unknown as WebpackPluginInstance, // webpack-bundle-analyzer has incorrect types
new RsdoctorRspackPlugin({}),
];
webpackConfig.stats = webpackStatsOptions;
webpackConfig.output = {
...webpackConfig.output,
path: tmpDir,
Expand Down
Loading