@@ -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,14 +141,8 @@ class WebpackFactory extends Factory {
141
141
this . __plugins [ plugin . alias ] = plugin ;
142
142
return this ;
143
143
}
144
-
145
144
146
145
const pluginObj = new Plugin ( ...args ) ;
147
- if ( this . __plugins [ pluginObj . alias ] ) {
148
- throw new Error (
149
- `${ pluginObj . alias } the plugin alias exsit! please change alias.`
150
- ) ;
151
- }
152
146
this . __plugins [ pluginObj . alias ] = pluginObj ;
153
147
return this ;
154
148
}
@@ -166,19 +160,13 @@ class WebpackFactory extends Factory {
166
160
}
167
161
168
162
setPlugin ( ...args ) {
169
- let pluginObj = { }
163
+ let pluginObj = { } ;
170
164
if ( args . length === 1 && args [ 0 ] . constructor === Plugin ) {
171
165
pluginObj = args [ 0 ] ;
172
- } else {
166
+ } else {
173
167
pluginObj = new Plugin ( ...args ) ;
174
168
}
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
- }
169
+ this . __plugins [ pluginObj . alias ] = pluginObj ;
182
170
return this ;
183
171
}
184
172
@@ -249,20 +237,20 @@ class WebpackFactory extends Factory {
249
237
250
238
251
239
setRule ( ...args ) {
252
- let ruleObj = { } ;
240
+ let ruleObj = { } ;
253
241
if ( args . length === 1 && args [ 0 ] . constructor === Rule ) {
254
- ruleObj = args [ 0 ]
255
- } else {
242
+ ruleObj = args [ 0 ] ;
243
+ } else {
256
244
ruleObj = new Rule ( ...args ) ;
257
245
}
258
-
246
+
259
247
let exsitRule = this . __rules . find ( v => v . alias . toString ( ) === ruleObj . alias . toString ( ) ) ;
260
- if ( ! exsitRule ) {
261
- throw new Error (
262
- `Set rule error, ${ args . join ( ',' ) } `
263
- ) ;
248
+ if ( exsitRule ) {
249
+ exsitRule = ruleObj ;
250
+ } else {
251
+ this . __rules . push ( ruleObj ) ;
264
252
}
265
- exsitRule = ruleObj ;
253
+
266
254
return this ;
267
255
}
268
256
@@ -273,23 +261,18 @@ class WebpackFactory extends Factory {
273
261
}
274
262
275
263
useRule ( filter ) {
276
-
277
264
const defineRules = Object . getPrototypeOf ( this ) . __defineRules ;
278
- if ( is . function ( filter ) ) {
265
+ if ( is . function ( filter ) ) {
279
266
return filter ( Object . values ( defineRules ) ) ;
280
267
}
281
- if ( is . regexp ( filter ) ) {
268
+ if ( is . regexp ( filter ) ) {
282
269
return defineRules [ filter . toString ( ) ] ;
283
270
}
284
- if ( is . string ( filter ) ) {
285
-
286
- return Object . values ( defineRules ) . find ( ( v ) => {
287
- return v . options . test . test ( filter ) ;
288
- } ) ;
271
+ if ( is . string ( filter ) ) {
272
+ return Object . values ( defineRules ) . find ( v => v . options . test . test ( filter ) ) ;
289
273
}
290
274
291
275
return null ;
292
-
293
276
}
294
277
295
278
getDefineRules ( ) {
0 commit comments