@@ -3,6 +3,7 @@ import path, { dirname, extname, isAbsolute, join } from 'node:path';
33import {
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 ,
0 commit comments