@@ -75,23 +75,10 @@ export async function createInternalRsbuildConfig(): Promise<RsbuildConfig> {
7575 return defineRsbuildConfig ( {
7676 tools : {
7777 htmlPlugin : false ,
78- rspack : {
79- output : {
80- module : true ,
81- library : {
82- type : 'module' ,
83- } ,
84- } ,
85- optimization : {
86- concatenateModules : true ,
87- } ,
88- experiments : {
89- outputModule : true ,
90- } ,
91- } ,
9278 } ,
9379 output : {
9480 filenameHash : false ,
81+ // TODO: easy to development at the moment
9582 minify : false ,
9683 distPath : {
9784 js : './' ,
@@ -104,36 +91,54 @@ export function convertLibConfigToRsbuildConfig(
10491 libConfig : LibConfig ,
10592 rsbuildConfig : RsbuildConfig ,
10693) : RsbuildConfig {
107- // TODO: Configuration mapping needs to be implemented according to features added in the future
108- if ( libConfig . format === 'cjs' ) {
109- mergeRsbuildConfig ( rsbuildConfig , {
110- tools : {
111- rspack : {
112- output : {
113- library : {
114- type : 'commonjs' ,
94+ switch ( libConfig . format ) {
95+ case 'esm' :
96+ return mergeRsbuildConfig ( rsbuildConfig , {
97+ tools : {
98+ rspack : {
99+ output : {
100+ module : true ,
101+ iife : false ,
102+ library : {
103+ type : 'modern-module' ,
104+ } ,
105+ } ,
106+ optimization : {
107+ concatenateModules : true ,
108+ } ,
109+ experiments : {
110+ outputModule : true ,
115111 } ,
116112 } ,
117113 } ,
118- } ,
119- } ) ;
120- }
121-
122- if ( libConfig . format === 'esm' ) {
123- mergeRsbuildConfig ( rsbuildConfig , {
124- tools : {
125- rspack : {
126- output : {
127- library : {
128- type : 'module' ,
114+ } ) ;
115+ case 'cjs' :
116+ return mergeRsbuildConfig ( rsbuildConfig , {
117+ tools : {
118+ rspack : {
119+ output : {
120+ library : {
121+ type : 'commonjs' ,
122+ } ,
129123 } ,
130124 } ,
131125 } ,
132- } ,
133- } ) ;
126+ } ) ;
127+ case 'umd' :
128+ return mergeRsbuildConfig ( rsbuildConfig , {
129+ tools : {
130+ rspack : {
131+ output : {
132+ library : {
133+ type : 'umd' ,
134+ } ,
135+ } ,
136+ } ,
137+ } ,
138+ } ) ;
139+ default :
140+ return rsbuildConfig ;
134141 }
135-
136- return rsbuildConfig ;
137142}
138143
139144export async function composeCreateRsbuildConfig (
@@ -151,6 +156,8 @@ export async function composeCreateRsbuildConfig(
151156 const composedRsbuildConfig = libConfigsArray . map ( ( libConfig : LibConfig ) => {
152157 const { format, ...overrideRsbuildConfig } = libConfig ;
153158
159+ // Merge order matters, keep `internalRsbuildConfig` at the last position
160+ // to ensure that the internal config is not overridden by the user's config.
154161 const mergedRsbuildConfig = mergeRsbuildConfig (
155162 sharedRsbuildConfig ,
156163 overrideRsbuildConfig ,
0 commit comments