-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (36 loc) · 1.08 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* 去掉 interface 的 warning */
// IgnoreWarningPlugin.js
const ModuleDependencyWarning = require('webpack/lib/ModuleDependencyWarning');
// https://github.com/TypeStrong/ts-loader/issues/653
// // ↓ Based on https://github.com/sindresorhus/escape-string-regexp
// const escapeStringForRegExp = string => string.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&');
module.exports = class IgnoreWarningPlugin {
constructor(option) {
const op = {
...option
};
if (op.warningFilter) this.warningFilter = op.warningFilter
}
warningFilter(warn) {
return true;
}
apply(compiler) {
const doneHook = stats => {
try {
stats.compilation.warnings = stats.compilation.warnings.filter(warn => {
if (!(warn instanceof ModuleDependencyWarning) || !warn.message) {
return true;
}
this.warningFilter(warn)
});
} catch (err) {
console.error(err)
}
};
if (compiler.hooks) {
compiler.hooks.done.tap('IgnoreWarningPlugin', doneHook);
} else {
compiler.plugin('done', doneHook);
}
}
};