@@ -75,23 +75,10 @@ export async function createInternalRsbuildConfig(): Promise<RsbuildConfig> {
75
75
return defineRsbuildConfig ( {
76
76
tools : {
77
77
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
- } ,
92
78
} ,
93
79
output : {
94
80
filenameHash : false ,
81
+ // TODO: easy to development at the moment
95
82
minify : false ,
96
83
distPath : {
97
84
js : './' ,
@@ -104,36 +91,54 @@ export function convertLibConfigToRsbuildConfig(
104
91
libConfig : LibConfig ,
105
92
rsbuildConfig : RsbuildConfig ,
106
93
) : 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 ,
115
111
} ,
116
112
} ,
117
113
} ,
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
+ } ,
129
123
} ,
130
124
} ,
131
125
} ,
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 ;
134
141
}
135
-
136
- return rsbuildConfig ;
137
142
}
138
143
139
144
export async function composeCreateRsbuildConfig (
@@ -151,6 +156,8 @@ export async function composeCreateRsbuildConfig(
151
156
const composedRsbuildConfig = libConfigsArray . map ( ( libConfig : LibConfig ) => {
152
157
const { format, ...overrideRsbuildConfig } = libConfig ;
153
158
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.
154
161
const mergedRsbuildConfig = mergeRsbuildConfig (
155
162
sharedRsbuildConfig ,
156
163
overrideRsbuildConfig ,
0 commit comments