Skip to content

Commit d0e8ff0

Browse files
committed
fix: 修复提交后的问题
1 parent 1d38a1d commit d0e8ff0

File tree

1 file changed

+17
-34
lines changed

1 file changed

+17
-34
lines changed

packages/beidou-webpack/lib/factory/webpack.js

+17-34
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class WebpackFactory extends Factory {
127127
addPlugin(...args) {
128128
if (args.length === 1 && is.string(args[0])) {
129129
if (this.usePlugin(args[0])) {
130-
const plugin = this.usePlugin(args[0]);
130+
const plugin = this.usePlugin(args[0]);
131131
this.__plugins[plugin.alias] = plugin;
132132
return this;
133133
} else {
@@ -141,14 +141,8 @@ class WebpackFactory extends Factory {
141141
this.__plugins[plugin.alias] = plugin;
142142
return this;
143143
}
144-
145144

146145
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-
}
152146
this.__plugins[pluginObj.alias] = pluginObj;
153147
return this;
154148
}
@@ -166,19 +160,13 @@ class WebpackFactory extends Factory {
166160
}
167161

168162
setPlugin(...args) {
169-
let pluginObj = {}
163+
let pluginObj = {};
170164
if (args.length === 1 && args[0].constructor === Plugin) {
171165
pluginObj = args[0];
172-
}else{
166+
} else {
173167
pluginObj = new Plugin(...args);
174168
}
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;
182170
return this;
183171
}
184172

@@ -249,20 +237,20 @@ class WebpackFactory extends Factory {
249237

250238

251239
setRule(...args) {
252-
let ruleObj = {};
240+
let ruleObj = {};
253241
if (args.length === 1 && args[0].constructor === Rule) {
254-
ruleObj = args[0]
255-
}else{
242+
ruleObj = args[0];
243+
} else {
256244
ruleObj = new Rule(...args);
257245
}
258-
246+
259247
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);
264252
}
265-
exsitRule = ruleObj;
253+
266254
return this;
267255
}
268256

@@ -273,23 +261,18 @@ class WebpackFactory extends Factory {
273261
}
274262

275263
useRule(filter) {
276-
277264
const defineRules = Object.getPrototypeOf(this).__defineRules;
278-
if(is.function(filter)){
265+
if (is.function(filter)) {
279266
return filter(Object.values(defineRules));
280267
}
281-
if(is.regexp(filter)){
268+
if (is.regexp(filter)) {
282269
return defineRules[filter.toString()];
283270
}
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));
289273
}
290274

291275
return null;
292-
293276
}
294277

295278
getDefineRules() {

0 commit comments

Comments
 (0)