@@ -10,6 +10,7 @@ import {
10
10
import {
11
11
BuilderPlugin ,
12
12
SharedBuilderConfig ,
13
+ ToolsBabelConfig ,
13
14
mergeBuilderConfig ,
14
15
} from '@modern-js/builder-shared' ;
15
16
import { CompileOptions } from '@storybook/mdx2-csf' ;
@@ -500,7 +501,6 @@ function addonAdapter(api: WebpackAPI | RspackAPI, options: Options) {
500
501
const replaceOrInsert = ( plugin : PluginItem , plugins : PluginItem [ ] ) => {
501
502
const pluginName = getPluginName ( plugin ) ;
502
503
503
- const append = [ ] ;
504
504
for ( let i = 0 ; i < plugins . length ; i ++ ) {
505
505
if ( getPluginName ( plugins [ i ] ) === pluginName ) {
506
506
if ( getOptions ( plugin ) ) {
@@ -509,12 +509,11 @@ function addonAdapter(api: WebpackAPI | RspackAPI, options: Options) {
509
509
) ;
510
510
plugins [ i ] = plugin ;
511
511
}
512
- } else {
513
- append . push ( plugin ) ;
512
+ return ;
514
513
}
515
514
}
516
515
517
- plugins . push ( ... append ) ;
516
+ plugins . push ( plugin ) ;
518
517
} ;
519
518
520
519
const currentPlugins = config . plugins || [ ] ;
@@ -528,17 +527,14 @@ function addonAdapter(api: WebpackAPI | RspackAPI, options: Options) {
528
527
replaceOrInsert ( preset , currentPresets ) ;
529
528
}
530
529
531
- const finalConfig = {
532
- ...config ,
530
+ const finalConfig : ToolsBabelConfig = {
533
531
...babelOptions ,
534
532
plugins : currentPlugins ,
535
533
presets : currentPresets ,
536
534
} ;
537
535
538
- if ( typeof userConfig === 'function' ) {
539
- return userConfig ( finalConfig , utils ) ;
540
- } else if ( typeof userConfig === 'object' ) {
541
- return { ...finalConfig , ...userConfig } ;
536
+ if ( userConfig ) {
537
+ return applyOptionsChain ( finalConfig , userConfig , utils ) ;
542
538
} else {
543
539
return finalConfig ;
544
540
}
0 commit comments