Skip to content

Commit 1d38a1d

Browse files
committed
fix: 初始化设置逻辑判断修改
1 parent 63d6ab2 commit 1d38a1d

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

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

+29-17
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,7 +141,7 @@ class WebpackFactory extends Factory {
141141
this.__plugins[plugin.alias] = plugin;
142142
return this;
143143
}
144-
144+
145145

146146
const pluginObj = new Plugin(...args);
147147
if (this.__plugins[pluginObj.alias]) {
@@ -166,13 +166,19 @@ class WebpackFactory extends Factory {
166166
}
167167

168168
setPlugin(...args) {
169-
let pluginObj = {};
169+
let pluginObj = {}
170170
if (args.length === 1 && args[0].constructor === Plugin) {
171171
pluginObj = args[0];
172-
} else {
172+
}else{
173173
pluginObj = new Plugin(...args);
174174
}
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+
}
176182
return this;
177183
}
178184

@@ -243,19 +249,20 @@ class WebpackFactory extends Factory {
243249

244250

245251
setRule(...args) {
246-
let ruleObj = {};
252+
let ruleObj = {};
247253
if (args.length === 1 && args[0].constructor === Rule) {
248-
ruleObj = args[0];
249-
} else {
254+
ruleObj = args[0]
255+
}else{
250256
ruleObj = new Rule(...args);
251257
}
252-
258+
253259
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+
);
258264
}
265+
exsitRule = ruleObj;
259266
return this;
260267
}
261268

@@ -266,18 +273,23 @@ class WebpackFactory extends Factory {
266273
}
267274

268275
useRule(filter) {
276+
269277
const defineRules = Object.getPrototypeOf(this).__defineRules;
270-
if (is.function(filter)) {
278+
if(is.function(filter)){
271279
return filter(Object.values(defineRules));
272280
}
273-
if (is.regexp(filter)) {
281+
if(is.regexp(filter)){
274282
return defineRules[filter.toString()];
275283
}
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+
});
278289
}
279290

280291
return null;
292+
281293
}
282294

283295
getDefineRules() {

0 commit comments

Comments
 (0)