IgnoreNotFoundExportPlugin.js 837 B

12345678910111213141516171819202122
  1. // https://github.com/TypeStrong/ts-loader/issues/653#issuecomment-390889335
  2. const ModuleDependencyWarning = require("webpack/lib/ModuleDependencyWarning")
  3. module.exports = class IgnoreNotFoundExportPlugin {
  4. apply(compiler) {
  5. const messageRegExp = /export '.*'( \(reexported as '.*'\))? was not found in/
  6. function doneHook(stats) {
  7. stats.compilation.warnings = stats.compilation.warnings.filter(function(warn) {
  8. if (warn instanceof ModuleDependencyWarning && messageRegExp.test(warn.message)) {
  9. return false
  10. }
  11. return true;
  12. })
  13. }
  14. if (compiler.hooks) {
  15. compiler.hooks.done.tap("IgnoreNotFoundExportPlugin", doneHook)
  16. } else {
  17. compiler.plugin("done", doneHook)
  18. }
  19. }
  20. }