@@ -453,6 +453,7 @@ export async function createConstantRsbuildConfig(): Promise<RsbuildConfig> {
453453 } ,
454454 } ,
455455 output : {
456+ target : 'node' ,
456457 filenameHash : false ,
457458 distPath : {
458459 js : './' ,
@@ -558,7 +559,6 @@ const composeFormatConfig = ({
558559 } ,
559560 output : {
560561 asyncChunks : false ,
561-
562562 library : umdName
563563 ? {
564564 type : 'umd' ,
@@ -713,8 +713,8 @@ const composeAutoExtensionConfig = (
713713} ;
714714
715715const composeSyntaxConfig = (
716+ target : RsbuildConfigOutputTarget ,
716717 syntax ?: Syntax ,
717- target ?: RsbuildConfigOutputTarget ,
718718) : RsbuildConfig => {
719719 // Defaults to ESNext, Rslib will assume all of the latest JavaScript and CSS features are supported.
720720 if ( syntax ) {
@@ -941,31 +941,40 @@ const composeDtsConfig = async (
941941} ;
942942
943943const composeTargetConfig = (
944- target : RsbuildConfigOutputTarget = 'web' ,
945- ) : RsbuildConfig => {
944+ target : RsbuildConfigOutputTarget = 'node' ,
945+ ) : {
946+ config : RsbuildConfig ;
947+ target : RsbuildConfigOutputTarget ;
948+ } => {
946949 switch ( target ) {
947950 case 'web' :
948951 return {
949- tools : {
950- rspack : {
951- target : [ 'web' ] ,
952+ config : {
953+ tools : {
954+ rspack : {
955+ target : [ 'web' ] ,
956+ } ,
952957 } ,
953958 } ,
959+ target : 'web' ,
954960 } ;
955961 case 'node' :
956962 return {
957- tools : {
958- rspack : {
959- target : [ 'node' ] ,
963+ config : {
964+ tools : {
965+ rspack : {
966+ target : [ 'node' ] ,
967+ } ,
968+ } ,
969+ output : {
970+ // When output.target is 'node', Node.js's built-in will be treated as externals of type `node-commonjs`.
971+ // Simply override the built-in modules to make them external.
972+ // https://github.com/webpack/webpack/blob/dd44b206a9c50f4b4cb4d134e1a0bd0387b159a3/lib/node/NodeTargetPlugin.js#L81
973+ externals : nodeBuiltInModules ,
974+ target : 'node' ,
960975 } ,
961976 } ,
962- output : {
963- // When output.target is 'node', Node.js's built-in will be treated as externals of type `node-commonjs`.
964- // Simply override the built-in modules to make them external.
965- // https://github.com/webpack/webpack/blob/dd44b206a9c50f4b4cb4d134e1a0bd0387b159a3/lib/node/NodeTargetPlugin.js#L81
966- externals : nodeBuiltInModules ,
967- target : 'node' ,
968- } ,
977+ target : 'node' ,
969978 } ;
970979 // TODO: Support `neutral` target, however Rsbuild don't list it as an option in the target field.
971980 // case 'neutral':
@@ -1067,11 +1076,10 @@ async function composeLibRsbuildConfig(config: LibConfig, configPath: string) {
10671076 cssModulesAuto ,
10681077 bundle ,
10691078 ) ;
1070- const targetConfig = composeTargetConfig ( config . output ?. target ) ;
1071- const syntaxConfig = composeSyntaxConfig (
1072- config ?. syntax ,
1079+ const { config : targetConfig , target } = composeTargetConfig (
10731080 config . output ?. target ,
10741081 ) ;
1082+ const syntaxConfig = composeSyntaxConfig ( target , config ?. syntax ) ;
10751083 const autoExternalConfig = composeAutoExternalConfig ( {
10761084 autoExternal,
10771085 pkgJson,
0 commit comments