Skip to content

Commit 5aecd25

Browse files
authored
perf: reduce the bundle size of client (#644)
1 parent a9c0b0f commit 5aecd25

File tree

15 files changed

+73
-38
lines changed

15 files changed

+73
-38
lines changed

packages/client/rsbuild.config.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export default defineConfig(({ env }) => {
146146
ids: true,
147147
version: true,
148148
entrypoints: true,
149+
optimizationBailout: true,
149150
});
150151
await fs.promises.writeFile(
151152
WebpackStatsFilePath,
@@ -161,13 +162,6 @@ export default defineConfig(({ env }) => {
161162
chainConfig.plugin('rsdoctor').use(RsdoctorRspackPlugin, [
162163
{
163164
disableClientServer: !ENABLE_CLIENT_SERVER,
164-
features: {
165-
loader: true,
166-
plugins: true,
167-
resolver: true,
168-
bundle: true,
169-
treeShaking: true,
170-
},
171165
},
172166
]);
173167
}

packages/components/src/pages/TreeShaking/table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { SDK } from '@rsdoctor/types';
2-
import {
2+
import type {
33
Module,
44
ModuleGraph,
55
Statement,

packages/components/src/pages/TreeShaking/utils.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { useMemo } from 'react';
22
import path from 'path-browserify';
33
import { escape, get } from 'lodash-es';
4-
import { Module, ModuleGraph, Statement, Variable } from '@rsdoctor/graph';
4+
import type { ModuleGraph, Statement, Variable } from '@rsdoctor/graph';
5+
import { Module } from '@rsdoctor/graph';
56
import { Tag, Space } from 'antd';
67
import { Range } from './range';
78
import type { editor, Range as RangeClass } from 'monaco-editor';

packages/graph/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
"dependencies": {
2323
"@rsdoctor/types": "workspace:*",
2424
"@rsdoctor/utils": "workspace:*",
25-
"lodash": "^4.17.21",
25+
"lodash.unionby": "^4.8.0",
2626
"socket.io": "4.8.1",
2727
"source-map": "^0.7.4"
2828
},
2929
"devDependencies": {
3030
"@types/body-parser": "1.19.5",
3131
"@types/estree": "1.0.5",
32-
"@types/lodash": "^4.17.13",
32+
"@types/lodash.unionby": "^4.8.9",
3333
"@types/node": "^16",
3434
"fs-extra": "^11.1.1",
3535
"tslib": "2.8.1",

packages/graph/src/graph/module-graph/module.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SDK } from '@rsdoctor/types';
22
import path from 'path';
3-
import { isNumber } from 'lodash';
3+
import { Lodash } from '@rsdoctor/utils/common';
44
import type { SourceMapConsumer } from 'source-map';
55
import type { Program } from 'estree';
66
import { Dependency } from './dependency';
@@ -263,7 +263,7 @@ export class Module implements SDK.ModuleInstance {
263263
bias: 1,
264264
});
265265

266-
if (isNumber(startInSource.line)) {
266+
if (Lodash.isNumber(startInSource.line)) {
267267
source.start = {
268268
line: startInSource.line,
269269
column: startInSource.column ?? undefined,
@@ -278,7 +278,7 @@ export class Module implements SDK.ModuleInstance {
278278
// bias: 2,
279279
});
280280

281-
if (isNumber(endInSource.line)) {
281+
if (Lodash.isNumber(endInSource.line)) {
282282
source.end = {
283283
line: endInSource.line,
284284
column: endInSource.column ?? undefined,

packages/graph/src/graph/module-graph/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { SDK } from '@rsdoctor/types';
2-
import { last, isUndefined, isNil } from 'lodash';
2+
import { Lodash } from '@rsdoctor/utils/common';
33

44
export function isSamePosition(
55
po1: SDK.SourcePosition,
@@ -13,11 +13,11 @@ export function isSameRange(po1: SDK.SourceRange, po2: SDK.SourceRange) {
1313
return false;
1414
}
1515

16-
if (!isNil(po1.end) && !isNil(po2.end)) {
16+
if (!Lodash.isNil(po1.end) && !Lodash.isNil(po2.end)) {
1717
return isSamePosition(po1.end, po2.end);
1818
}
1919

20-
return isUndefined(po1.end) && isUndefined(po2.end);
20+
return Lodash.isUndefined(po1.end) && Lodash.isUndefined(po2.end);
2121
}
2222

2323
/**
@@ -44,7 +44,7 @@ export function getModuleName(name?: string) {
4444
}
4545

4646
if (NAME_WITH_LOADERS.test(name)) {
47-
const normalizedName = last(name.split(NAME_WITH_LOADERS));
47+
const normalizedName = Lodash.last(name.split(NAME_WITH_LOADERS));
4848

4949
if (normalizedName?.trim()) {
5050
return normalizedName;

packages/graph/src/graph/package-graph/graph.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { unionBy } from 'lodash';
2-
import { dirname, join, resolve } from 'path';
1+
import unionBy from 'lodash.unionby';
2+
import { resolve } from 'path';
33
import { SDK } from '@rsdoctor/types';
44
import type { ModuleGraph, Module } from '../module-graph';
55
import { Package } from './package';

packages/utils/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@
8888
"get-port": "5.1.1",
8989
"json-stream-stringify": "3.0.1",
9090
"lines-and-columns": "2.0.4",
91-
"lodash": "^4.17.21",
9291
"rslog": "^1.2.3",
9392
"strip-ansi": "^6.0.1"
9493
},
@@ -98,7 +97,6 @@
9897
"@types/deep-eql": "4.0.2",
9998
"@types/envinfo": "7.8.4",
10099
"@types/fs-extra": "^11.0.4",
101-
"@types/lodash": "^4.17.13",
102100
"@types/node": "^16",
103101
"tslib": "2.8.1",
104102
"typescript": "^5.2.2"

packages/utils/src/common/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ export * as Data from './data';
1313
export * as Alerts from './alerts';
1414
export * as Rspack from './rspack';
1515
export * as Package from './package';
16+
export * as Lodash from './lodash';
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Replace lodash's isUndefined function
2+
export function isUndefined(value: unknown): value is undefined {
3+
return typeof value === 'undefined';
4+
}
5+
6+
// Replace lodash's isNumber function
7+
export function isNumber(value: unknown): value is number {
8+
return typeof value === 'number' && !Number.isNaN(value);
9+
}
10+
11+
export function isObject(value: unknown): value is Record<string, unknown> {
12+
return typeof value === 'object' && value !== null;
13+
}
14+
15+
// Replace lodash's isEmpty function
16+
export function isEmpty(value: unknown): boolean {
17+
return (
18+
value == null || // Check for null or undefined
19+
(Array.isArray(value) && value.length === 0) || // Check for empty array
20+
(typeof value === 'object' && Object.keys(value).length === 0) // Check for empty object
21+
);
22+
}
23+
24+
// Replace lodash's last function
25+
export function last<T>(array: T[]): T | undefined {
26+
return array[array.length - 1];
27+
}
28+
29+
// Replace lodash's compact function
30+
export function compact<T>(array: (T | null | undefined)[]): T[] {
31+
return array.filter((item): item is T => item != null || !item); // Filter out null and undefined
32+
}
33+
34+
// Replace lodash's isNil function
35+
export function isNil(value: unknown): value is null | undefined {
36+
return value === null || value === undefined;
37+
}

0 commit comments

Comments
 (0)