2019-01-20 21:13:55 +08:00
|
|
|
// We should use `stats` props of webpack. But it not work in v4.
|
|
|
|
class CleanUpStatsPlugin {
|
|
|
|
constructor(option) {
|
|
|
|
this.option = {
|
|
|
|
MiniCSSExtractPlugin: true,
|
|
|
|
tsLoader: true,
|
|
|
|
...option,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
shouldPickStatChild(child) {
|
|
|
|
const { MiniCSSExtractPlugin } = this.option;
|
|
|
|
if (MiniCSSExtractPlugin && child.name.includes('mini-css-extract-plugin')) return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
shouldPickWarning(message) {
|
|
|
|
const { tsLoader } = this.option;
|
|
|
|
if (tsLoader && /export .* was not found in .*/.test(message)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
apply(compiler) {
|
|
|
|
compiler.hooks.done.tap('CleanUpStatsPlugin', stats => {
|
2019-01-27 11:43:55 +08:00
|
|
|
const { children } = stats.compilation;
|
2019-01-20 21:13:55 +08:00
|
|
|
if (Array.isArray(children)) {
|
|
|
|
stats.compilation.children = children.filter(child => this.shouldPickStatChild(child));
|
|
|
|
}
|
2019-01-27 11:43:55 +08:00
|
|
|
// if (Array.isArray(warnings)) {
|
|
|
|
// stats.compilation.warnings = warnings.filter(message => this.shouldPickWarning(message));
|
|
|
|
// }
|
2019-01-20 21:13:55 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = CleanUpStatsPlugin;
|