@@ -163,21 +163,27 @@ const finalize = async (moduleObj, args) => {
163163 const newOptions = configOptions ( formattedEnv , args ) ;
164164 // When config function returns a promise, resolve it, if not it's resolved by default
165165 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+ }
173177 } else {
174- newOptionsObject [ 'options' ] = namedOptions ;
178+ logger . error ( 'Multiple configurations not found. Please use "--config-name" with multiple configurations.' ) ;
179+ process . exit ( 2 ) ;
175180 }
176181 } else {
177182 if ( Array . isArray ( configOptions ) && ! configOptions . length ) {
178183 newOptionsObject [ 'options' ] = { } ;
179184 return newOptionsObject ;
180185 }
186+
181187 newOptionsObject [ 'options' ] = configOptions ;
182188 }
183189
0 commit comments