@@ -163,21 +163,27 @@ const finalize = async (moduleObj, args) => {
163
163
const newOptions = configOptions ( formattedEnv , args ) ;
164
164
// When config function returns a promise, resolve it, if not it's resolved by default
165
165
newOptionsObject [ 'options' ] = await Promise . resolve ( newOptions ) ;
166
- } else if ( Array . isArray ( configOptions ) && configName ) {
167
- // In case of exporting multiple configurations, If you pass a name to --config-name flag,
168
- // webpack will only build that specific configuration.
169
- const namedOptions = configOptions . filter ( ( opt ) => configName . includes ( opt . name ) ) ;
170
- if ( namedOptions . length === 0 ) {
171
- logger . error ( `Configuration with name "${ configName } " was not found.` ) ;
172
- process . exit ( 2 ) ;
166
+ } else if ( configName ) {
167
+ if ( Array . isArray ( configOptions ) && configOptions . length > 1 ) {
168
+ // In case of exporting multiple configurations, If you pass a name to --config-name flag,
169
+ // webpack will only build that specific configuration.
170
+ const namedOptions = configOptions . filter ( ( opt ) => configName . includes ( opt . name ) ) ;
171
+ if ( namedOptions . length === 0 ) {
172
+ logger . error ( `Configuration with name "${ configName } " was not found.` ) ;
173
+ process . exit ( 2 ) ;
174
+ } else {
175
+ newOptionsObject [ 'options' ] = namedOptions ;
176
+ }
173
177
} else {
174
- newOptionsObject [ 'options' ] = namedOptions ;
178
+ logger . error ( 'Multiple configurations not found. Please use "--config-name" with multiple configurations.' ) ;
179
+ process . exit ( 2 ) ;
175
180
}
176
181
} else {
177
182
if ( Array . isArray ( configOptions ) && ! configOptions . length ) {
178
183
newOptionsObject [ 'options' ] = { } ;
179
184
return newOptionsObject ;
180
185
}
186
+
181
187
newOptionsObject [ 'options' ] = configOptions ;
182
188
}
183
189
0 commit comments