diff --git a/examples/module-federation/mf-react-component/rslib.config.ts b/examples/module-federation/mf-react-component/rslib.config.ts index 271828b2d..4dff69848 100644 --- a/examples/module-federation/mf-react-component/rslib.config.ts +++ b/examples/module-federation/mf-react-component/rslib.config.ts @@ -62,8 +62,5 @@ export default defineConfig({ ], }, ], - output: { - target: 'web', - }, plugins: [pluginReact()], }); diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index 2c9114ce4..cc41c223c 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -581,7 +581,6 @@ const composeFormatConfig = ({ output: { uniqueName: pkgJson.name as string, }, - // TODO when we provide dev mode for rslib mf format, this should be modified to as the same with config.mode // can not set nodeEnv to false, because mf format should build shared module. // If nodeEnv is false, the process.env.NODE_ENV in third-party packages's will not be replaced // now we have not provide dev mode for users, so we can always set nodeEnv as 'production' @@ -590,6 +589,9 @@ const composeFormatConfig = ({ }, }, }, + output: { + target: 'web', + }, }; default: throw new Error(`Unsupported format: ${format}`); @@ -941,12 +943,17 @@ const composeDtsConfig = async ( }; const composeTargetConfig = ( - target: RsbuildConfigOutputTarget = 'node', + target: RsbuildConfigOutputTarget, + format: Format, ): { config: RsbuildConfig; target: RsbuildConfigOutputTarget; } => { - switch (target) { + let defaultTarget = target; + if (!defaultTarget) { + defaultTarget = format === 'mf' ? 'web' : 'node'; + } + switch (defaultTarget) { case 'web': return { config: { @@ -986,7 +993,7 @@ const composeTargetConfig = ( // }, // }; default: - throw new Error(`Unsupported platform: ${target}`); + throw new Error(`Unsupported platform: ${defaultTarget}`); } }; @@ -1078,6 +1085,7 @@ async function composeLibRsbuildConfig(config: LibConfig, configPath: string) { ); const { config: targetConfig, target } = composeTargetConfig( config.output?.target, + format!, ); const syntaxConfig = composeSyntaxConfig(target, config?.syntax); const autoExternalConfig = composeAutoExternalConfig({