@@ -102,7 +102,7 @@ class WebpackBaseBuilder extends Config {
102
102
} else if ( this . utils . isObject ( plugin ) && this . utils . isFunction ( plugin . name ) && plugin . name . name ) {
103
103
sourcePlugins [ plugin . name . name ] = plugin ;
104
104
}
105
- } else if ( this . utils . isFunction ( plugin . apply ) ) { // only apply method plugin
105
+ } else if ( this . isWebpackApplyPlugin ( plugin ) ) { // only apply method plugin
106
106
const label = this . utils . getPluginLabel ( plugin ) ;
107
107
sourcePlugins [ label ] = { name : plugin } ;
108
108
} else if ( Object . keys ( plugin ) . length === 1 ) {
@@ -124,32 +124,31 @@ class WebpackBaseBuilder extends Config {
124
124
target [ name ] . enable = configPlugin . enable . apply ( this ) ;
125
125
} else if ( this . utils . isBoolean ( configPlugin ) ) {
126
126
target [ name ] . enable = configPlugin ;
127
- } else if ( configPlugin . name || this . isWebpackPlugin ( configPlugin ) ) { // 直接覆盖
127
+ } else if ( configPlugin . name || this . isWebpackPlugin ( configPlugin ) || this . isWebpackApplyPlugin ( configPlugin ) ) { // 直接覆盖
128
128
target [ name ] = configPlugin ;
129
129
} else {
130
- // 如果 name 和 args 不存在, configPlugin直接作为args , 配置是可以省去 args key
130
+ // 如果 name 和 args 不存在, configPlugin 直接作为args , 配置是可以省去 args key
131
131
const args = configPlugin . args ? configPlugin . args : configPlugin ;
132
+ const nomalizeArgs = Array . isArray ( args ) ? [ args ] : args ;
132
133
if ( target [ name ] . concatArgs ) {
133
- target [ name ] . concatArgs = target [ name ] . concatArgs . concat ( args ) ;
134
+ target [ name ] . concatArgs = target [ name ] . concatArgs . concat ( nomalizeArgs ) ;
134
135
} else {
135
- target [ name ] . concatArgs = [ ] . concat ( target [ name ] . args ) . concat ( args ) ;
136
+ target [ name ] . concatArgs = [ ] . concat ( target [ name ] . args || [ ] ) . concat ( nomalizeArgs ) ;
136
137
}
137
138
const cloneConfigPlugin = this . utils . cloneDeep ( configPlugin ) ;
138
139
delete cloneConfigPlugin . enable ;
139
140
delete cloneConfigPlugin . args ;
140
141
target [ name ] = this . merge ( target [ name ] , cloneConfigPlugin ) ;
141
142
}
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 ) ) {
145
144
target [ name ] = configPlugin ;
146
145
}
147
146
} ) ;
148
147
149
148
return target ;
150
149
}
151
150
152
- parsePluginArgs ( plugin ) {
151
+ parsePluginArgs ( plugin , label ) {
153
152
try {
154
153
const args = this . utils . isFunction ( plugin . args ) ? plugin . args . apply ( this ) : plugin . args ;
155
154
const concatArgs = ( plugin . concatArgs || [ ] ) . map ( arg => {
@@ -172,7 +171,7 @@ class WebpackBaseBuilder extends Config {
172
171
}
173
172
}
174
173
} ) ;
175
- return concatArgs [ 0 ] ;
174
+ return concatArgs ;
176
175
}
177
176
if ( Array . isArray ( args ) || this . utils . isString ( args ) || this . utils . isBoolean ( args ) || ( this . utils . isObject ( args ) && args . test ) ) { // override
178
177
return concatArgs [ length - 1 ] ;
@@ -181,7 +180,7 @@ class WebpackBaseBuilder extends Config {
181
180
return this . merge ( arg , itemArgs ) ;
182
181
} , args ) ;
183
182
} catch ( e ) {
184
- console . error ( 'parsePluginArgs:' , plugin , e ) ;
183
+ console . error ( 'parsePluginArgs:' , label , plugin , e ) ;
185
184
}
186
185
}
187
186
@@ -408,8 +407,8 @@ class WebpackBaseBuilder extends Config {
408
407
409
408
createPlugin ( plugins ) {
410
409
const webpackPlugins = [ ] ;
411
- Object . keys ( plugins ) . forEach ( name => {
412
- const configInfo = plugins [ name ] ;
410
+ Object . keys ( plugins ) . forEach ( label => {
411
+ const configInfo = plugins [ label ] ;
413
412
if ( this . isUse ( configInfo ) ) {
414
413
let plugin ;
415
414
let pluginName ;
@@ -418,10 +417,10 @@ class WebpackBaseBuilder extends Config {
418
417
pluginName = configInfo . constructor . name ;
419
418
} else if ( this . utils . isObject ( configInfo . name ) ) { // plugin object
420
419
plugin = configInfo . name ;
421
- pluginName = plugin . constructor && plugin . constructor . name || name ;
420
+ pluginName = plugin . constructor && plugin . constructor . name || label ;
422
421
} else if ( this . utils . isObject ( configInfo ) && this . utils . isFunction ( configInfo . apply ) ) {
423
422
plugin = configInfo ;
424
- pluginName = name ;
423
+ pluginName = label ;
425
424
} else if ( this . utils . isString ( configInfo . name ) || this . utils . isFunction ( configInfo . name ) ) {
426
425
let Clazz = configInfo . name ;
427
426
if ( this . utils . isString ( configInfo . name ) ) {
@@ -430,7 +429,7 @@ class WebpackBaseBuilder extends Config {
430
429
} else if ( this . utils . isFunction ( configInfo . name ) ) {
431
430
pluginName = configInfo . name . name ;
432
431
}
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
434
433
${ chalk . green ( 'npm' ) } : easy install --mode npm | npx easy install --mode npm\r\n
435
434
${ chalk . green ( 'cnpm' ) } : easy install --mode cnpm | npx easy install --mode cnpm\r\n
436
435
${ chalk . green ( 'tnpm' ) } : easy install --mode tnpm | npx easy install --mode tnpm\r\n
@@ -445,15 +444,15 @@ class WebpackBaseBuilder extends Config {
445
444
Clazz = Clazz [ configInfo . entry ] ;
446
445
}
447
446
if ( configInfo . args || configInfo . concatArgs ) {
448
- const args = this . parsePluginArgs ( configInfo ) ;
447
+ const args = this . parsePluginArgs ( configInfo , label ) ;
449
448
plugin = new ( Function . prototype . bind . apply ( Clazz , [ null ] . concat ( args ) ) ) ( ) ;
450
449
} else {
451
450
plugin = new Clazz ( ) ;
452
451
}
453
452
}
454
453
if ( plugin ) {
455
454
plugin . __plugin__ = pluginName ;
456
- plugin . __lable__ = name ;
455
+ plugin . __lable__ = label ;
457
456
webpackPlugins . push ( plugin ) ;
458
457
}
459
458
}
0 commit comments