@@ -102,7 +102,7 @@ class WebpackBaseBuilder extends Config {
102102 } else if ( this . utils . isObject ( plugin ) && this . utils . isFunction ( plugin . name ) && plugin . name . name ) {
103103 sourcePlugins [ plugin . name . name ] = plugin ;
104104 }
105- } else if ( this . utils . isFunction ( plugin . apply ) ) { // only apply method plugin
105+ } else if ( this . isWebpackApplyPlugin ( plugin ) ) { // only apply method plugin
106106 const label = this . utils . getPluginLabel ( plugin ) ;
107107 sourcePlugins [ label ] = { name : plugin } ;
108108 } else if ( Object . keys ( plugin ) . length === 1 ) {
@@ -124,32 +124,31 @@ class WebpackBaseBuilder extends Config {
124124 target [ name ] . enable = configPlugin . enable . apply ( this ) ;
125125 } else if ( this . utils . isBoolean ( configPlugin ) ) {
126126 target [ name ] . enable = configPlugin ;
127- } else if ( configPlugin . name || this . isWebpackPlugin ( configPlugin ) ) { // 直接覆盖
127+ } else if ( configPlugin . name || this . isWebpackPlugin ( configPlugin ) || this . isWebpackApplyPlugin ( configPlugin ) ) { // 直接覆盖
128128 target [ name ] = configPlugin ;
129129 } else {
130- // 如果 name 和 args 不存在, configPlugin直接作为args , 配置是可以省去 args key
130+ // 如果 name 和 args 不存在, configPlugin 直接作为args , 配置是可以省去 args key
131131 const args = configPlugin . args ? configPlugin . args : configPlugin ;
132+ const nomalizeArgs = Array . isArray ( args ) ? [ args ] : args ;
132133 if ( target [ name ] . concatArgs ) {
133- target [ name ] . concatArgs = target [ name ] . concatArgs . concat ( args ) ;
134+ target [ name ] . concatArgs = target [ name ] . concatArgs . concat ( nomalizeArgs ) ;
134135 } else {
135- target [ name ] . concatArgs = [ ] . concat ( target [ name ] . args ) . concat ( args ) ;
136+ target [ name ] . concatArgs = [ ] . concat ( target [ name ] . args || [ ] ) . concat ( nomalizeArgs ) ;
136137 }
137138 const cloneConfigPlugin = this . utils . cloneDeep ( configPlugin ) ;
138139 delete cloneConfigPlugin . enable ;
139140 delete cloneConfigPlugin . args ;
140141 target [ name ] = this . merge ( target [ name ] , cloneConfigPlugin ) ;
141142 }
142- } else if ( this . isWebpackPlugin ( configPlugin ) || this . isConfigPlugin ( configPlugin ) ) {
143- target [ name ] = configPlugin ;
144- } else if ( this . utils . isObject ( configPlugin ) && this . utils . isFunction ( configPlugin . apply ) ) {
143+ } else if ( this . isWebpackPlugin ( configPlugin ) || this . isWebpackApplyPlugin ( configPlugin ) || this . isConfigPlugin ( configPlugin ) ) {
145144 target [ name ] = configPlugin ;
146145 }
147146 } ) ;
148147
149148 return target ;
150149 }
151150
152- parsePluginArgs ( plugin ) {
151+ parsePluginArgs ( plugin , label ) {
153152 try {
154153 const args = this . utils . isFunction ( plugin . args ) ? plugin . args . apply ( this ) : plugin . args ;
155154 const concatArgs = ( plugin . concatArgs || [ ] ) . map ( arg => {
@@ -172,7 +171,7 @@ class WebpackBaseBuilder extends Config {
172171 }
173172 }
174173 } ) ;
175- return concatArgs [ 0 ] ;
174+ return concatArgs ;
176175 }
177176 if ( Array . isArray ( args ) || this . utils . isString ( args ) || this . utils . isBoolean ( args ) || ( this . utils . isObject ( args ) && args . test ) ) { // override
178177 return concatArgs [ length - 1 ] ;
@@ -181,7 +180,7 @@ class WebpackBaseBuilder extends Config {
181180 return this . merge ( arg , itemArgs ) ;
182181 } , args ) ;
183182 } catch ( e ) {
184- console . error ( 'parsePluginArgs:' , plugin , e ) ;
183+ console . error ( 'parsePluginArgs:' , label , plugin , e ) ;
185184 }
186185 }
187186
@@ -408,8 +407,8 @@ class WebpackBaseBuilder extends Config {
408407
409408 createPlugin ( plugins ) {
410409 const webpackPlugins = [ ] ;
411- Object . keys ( plugins ) . forEach ( name => {
412- const configInfo = plugins [ name ] ;
410+ Object . keys ( plugins ) . forEach ( label => {
411+ const configInfo = plugins [ label ] ;
413412 if ( this . isUse ( configInfo ) ) {
414413 let plugin ;
415414 let pluginName ;
@@ -418,10 +417,10 @@ class WebpackBaseBuilder extends Config {
418417 pluginName = configInfo . constructor . name ;
419418 } else if ( this . utils . isObject ( configInfo . name ) ) { // plugin object
420419 plugin = configInfo . name ;
421- pluginName = plugin . constructor && plugin . constructor . name || name ;
420+ pluginName = plugin . constructor && plugin . constructor . name || label ;
422421 } else if ( this . utils . isObject ( configInfo ) && this . utils . isFunction ( configInfo . apply ) ) {
423422 plugin = configInfo ;
424- pluginName = name ;
423+ pluginName = label ;
425424 } else if ( this . utils . isString ( configInfo . name ) || this . utils . isFunction ( configInfo . name ) ) {
426425 let Clazz = configInfo . name ;
427426 if ( this . utils . isString ( configInfo . name ) ) {
@@ -430,7 +429,7 @@ class WebpackBaseBuilder extends Config {
430429 } else if ( this . utils . isFunction ( configInfo . name ) ) {
431430 pluginName = configInfo . name . name ;
432431 }
433- assert ( Clazz , chalk . red ( `dynamic create plugin[${ name } ] error, please check the npm module [${ pluginName } ] whether installed. ${ chalk . yellow ( 'if not installed, please execute below command in command line:' ) } \r\n
432+ assert ( Clazz , chalk . red ( `dynamic create plugin[${ label } ] error, please check the npm module [${ pluginName } ] whether installed. ${ chalk . yellow ( 'if not installed, please execute below command in command line:' ) } \r\n
434433 ${ chalk . green ( 'npm' ) } : easy install --mode npm | npx easy install --mode npm\r\n
435434 ${ chalk . green ( 'cnpm' ) } : easy install --mode cnpm | npx easy install --mode cnpm\r\n
436435 ${ chalk . green ( 'tnpm' ) } : easy install --mode tnpm | npx easy install --mode tnpm\r\n
@@ -445,15 +444,15 @@ class WebpackBaseBuilder extends Config {
445444 Clazz = Clazz [ configInfo . entry ] ;
446445 }
447446 if ( configInfo . args || configInfo . concatArgs ) {
448- const args = this . parsePluginArgs ( configInfo ) ;
447+ const args = this . parsePluginArgs ( configInfo , label ) ;
449448 plugin = new ( Function . prototype . bind . apply ( Clazz , [ null ] . concat ( args ) ) ) ( ) ;
450449 } else {
451450 plugin = new Clazz ( ) ;
452451 }
453452 }
454453 if ( plugin ) {
455454 plugin . __plugin__ = pluginName ;
456- plugin . __lable__ = name ;
455+ plugin . __lable__ = label ;
457456 webpackPlugins . push ( plugin ) ;
458457 }
459458 }
0 commit comments