FlagAllModulesAsUsedPlugin.js 788 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. /** @typedef {import("./Compiler")} Compiler */
  7. class FlagAllModulesAsUsedPlugin {
  8. constructor(explanation) {
  9. this.explanation = explanation;
  10. }
  11. /**
  12. * @param {Compiler} compiler webpack compiler
  13. * @returns {void}
  14. */
  15. apply(compiler) {
  16. compiler.hooks.compilation.tap(
  17. "FlagAllModulesAsUsedPlugin",
  18. compilation => {
  19. compilation.hooks.optimizeDependencies.tap(
  20. "FlagAllModulesAsUsedPlugin",
  21. modules => {
  22. for (const module of modules) {
  23. module.used = true;
  24. module.usedExports = true;
  25. module.addReason(null, null, this.explanation);
  26. }
  27. }
  28. );
  29. }
  30. );
  31. }
  32. }
  33. module.exports = FlagAllModulesAsUsedPlugin;