Skip to content

Commit 2c6c888

Browse files
committed
perf: enable compress minify option for node target
1 parent 567c514 commit 2c6c888

File tree

3 files changed

+26
-35
lines changed

3 files changed

+26
-35
lines changed

packages/core/src/config.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path, { dirname, extname, isAbsolute, join } from 'node:path';
33
import {
44
type EnvironmentConfig,
55
type RsbuildConfig,
6+
type RsbuildTarget,
67
defineConfig as defineRsbuildConfig,
78
loadConfig as loadRsbuildConfig,
89
mergeRsbuildConfig,
@@ -285,14 +286,18 @@ export const composeAutoExternalConfig = (options: {
285286
: {};
286287
};
287288

288-
export function composeMinifyConfig(config: LibConfig): RsbuildConfig {
289+
export function composeMinifyConfig(
290+
config: LibConfig,
291+
target?: RsbuildTarget,
292+
): RsbuildConfig {
289293
const minify = config.output?.minify;
290-
const format = config.format;
291294
if (minify !== undefined) {
292295
// User's minify configuration will be merged afterwards.
293296
return {};
294297
}
295298

299+
const format = config.format;
300+
296301
// When minify is not specified, Rslib will use a sane default for minify options.
297302
// The default options will only perform dead code elimination and unused code elimination.
298303
return {
@@ -303,15 +308,21 @@ export function composeMinifyConfig(config: LibConfig): RsbuildConfig {
303308
jsOptions: {
304309
minimizerOptions: {
305310
mangle: false,
306-
// MF assets are loaded over the network, which means they will not be compressed by the project. Therefore, minifying them is necessary.
311+
// MF assets are loaded over the network, which means they will not be compressed by the project.
312+
// Therefore, minifying them is necessary.
307313
minify: format === 'mf',
308-
compress: {
309-
defaults: false,
310-
unused: true,
311-
dead_code: true,
312-
// remoteEntry's global variable will be tree-shaken if `toplevel` is enabled in "mf" format
313-
toplevel: format !== 'mf',
314-
},
314+
compress:
315+
// For the Node target, keep output bundles as small as possible while retaining the necessary information
316+
// for debugging, as Node outputs usually executed directly at runtime rather than being built again.
317+
target === 'node'
318+
? true
319+
: {
320+
defaults: false,
321+
unused: true,
322+
dead_code: true,
323+
// remoteEntry's global variable will be tree-shaken if `toplevel` is enabled in "mf" format
324+
toplevel: format !== 'mf',
325+
},
315326
format: {
316327
comments: 'all',
317328
},
@@ -1106,7 +1117,7 @@ async function composeLibRsbuildConfig(config: LibConfig, configPath: string) {
11061117
autoExternalConfig?.output?.externals,
11071118
externalsConfig?.output?.externals,
11081119
);
1109-
const minifyConfig = composeMinifyConfig(config);
1120+
const minifyConfig = composeMinifyConfig(config, target);
11101121
const bannerFooterConfig = composeBannerFooterConfig(banner, footer);
11111122
const decoratorsConfig = composeDecoratorsConfig(
11121123
compilerOptions,

packages/core/tests/__snapshots__/config.test.ts.snap

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,7 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1
8080
"js": true,
8181
"jsOptions": {
8282
"minimizerOptions": {
83-
"compress": {
84-
"dead_code": true,
85-
"defaults": false,
86-
"toplevel": true,
87-
"unused": true,
88-
},
83+
"compress": true,
8984
"format": {
9085
"comments": "all",
9186
},
@@ -292,12 +287,7 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1
292287
"js": true,
293288
"jsOptions": {
294289
"minimizerOptions": {
295-
"compress": {
296-
"dead_code": true,
297-
"defaults": false,
298-
"toplevel": true,
299-
"unused": true,
300-
},
290+
"compress": true,
301291
"format": {
302292
"comments": "all",
303293
},
@@ -502,12 +492,7 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1
502492
"js": true,
503493
"jsOptions": {
504494
"minimizerOptions": {
505-
"compress": {
506-
"dead_code": true,
507-
"defaults": false,
508-
"toplevel": true,
509-
"unused": true,
510-
},
495+
"compress": true,
511496
"format": {
512497
"comments": "all",
513498
},

packages/core/tests/config.test.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,7 @@ describe('minify', () => {
332332
"js": true,
333333
"jsOptions": {
334334
"minimizerOptions": {
335-
"compress": {
336-
"dead_code": true,
337-
"defaults": false,
338-
"toplevel": true,
339-
"unused": true,
340-
},
335+
"compress": true,
341336
"format": {
342337
"comments": "all",
343338
},

0 commit comments

Comments
 (0)