@@ -127,7 +127,7 @@ class WebpackFactory extends Factory {
127
127
addPlugin ( ...args ) {
128
128
if ( args . length === 1 && is . string ( args [ 0 ] ) ) {
129
129
if ( this . usePlugin ( args [ 0 ] ) ) {
130
- const plugin = this . usePlugin ( args [ 0 ] ) ;
130
+ const plugin = this . usePlugin ( args [ 0 ] ) ;
131
131
this . __plugins [ plugin . alias ] = plugin ;
132
132
return this ;
133
133
} else {
@@ -141,7 +141,7 @@ class WebpackFactory extends Factory {
141
141
this . __plugins [ plugin . alias ] = plugin ;
142
142
return this ;
143
143
}
144
-
144
+
145
145
146
146
const pluginObj = new Plugin ( ...args ) ;
147
147
if ( this . __plugins [ pluginObj . alias ] ) {
@@ -166,13 +166,19 @@ class WebpackFactory extends Factory {
166
166
}
167
167
168
168
setPlugin ( ...args ) {
169
- let pluginObj = { } ;
169
+ let pluginObj = { }
170
170
if ( args . length === 1 && args [ 0 ] . constructor === Plugin ) {
171
171
pluginObj = args [ 0 ] ;
172
- } else {
172
+ } else {
173
173
pluginObj = new Plugin ( ...args ) ;
174
174
}
175
- this . __plugins [ pluginObj . alias ] = pluginObj ;
175
+ if ( this . __plugins [ pluginObj . alias ] ) {
176
+ this . __plugins [ pluginObj . alias ] = pluginObj ;
177
+ } else {
178
+ throw new Error (
179
+ `${ pluginObj . alias } the Plugin not exsit! `
180
+ ) ;
181
+ }
176
182
return this ;
177
183
}
178
184
@@ -243,19 +249,20 @@ class WebpackFactory extends Factory {
243
249
244
250
245
251
setRule ( ...args ) {
246
- let ruleObj = { } ;
252
+ let ruleObj = { } ;
247
253
if ( args . length === 1 && args [ 0 ] . constructor === Rule ) {
248
- ruleObj = args [ 0 ] ;
249
- } else {
254
+ ruleObj = args [ 0 ]
255
+ } else {
250
256
ruleObj = new Rule ( ...args ) ;
251
257
}
252
-
258
+
253
259
let exsitRule = this . __rules . find ( v => v . alias . toString ( ) === ruleObj . alias . toString ( ) ) ;
254
- if ( exsitRule ) {
255
- exsitRule = ruleObj ;
256
- } else {
257
- this . __rules . push ( ruleObj ) ;
260
+ if ( ! exsitRule ) {
261
+ throw new Error (
262
+ `Set rule error, ${ args . join ( ',' ) } `
263
+ ) ;
258
264
}
265
+ exsitRule = ruleObj ;
259
266
return this ;
260
267
}
261
268
@@ -266,18 +273,23 @@ class WebpackFactory extends Factory {
266
273
}
267
274
268
275
useRule ( filter ) {
276
+
269
277
const defineRules = Object . getPrototypeOf ( this ) . __defineRules ;
270
- if ( is . function ( filter ) ) {
278
+ if ( is . function ( filter ) ) {
271
279
return filter ( Object . values ( defineRules ) ) ;
272
280
}
273
- if ( is . regexp ( filter ) ) {
281
+ if ( is . regexp ( filter ) ) {
274
282
return defineRules [ filter . toString ( ) ] ;
275
283
}
276
- if ( is . string ( filter ) ) {
277
- return Object . values ( defineRules ) . find ( v => v . options . test . test ( filter ) ) ;
284
+ if ( is . string ( filter ) ) {
285
+
286
+ return Object . values ( defineRules ) . find ( ( v ) => {
287
+ return v . options . test . test ( filter ) ;
288
+ } ) ;
278
289
}
279
290
280
291
return null ;
292
+
281
293
}
282
294
283
295
getDefineRules ( ) {
0 commit comments