FlagInitialModulesAsUsedPlugin.js 799 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. class FlagInitialModulesAsUsedPlugin {
  7. constructor(explanation) {
  8. this.explanation = explanation;
  9. }
  10. apply(compiler) {
  11. compiler.hooks.compilation.tap(
  12. "FlagInitialModulesAsUsedPlugin",
  13. compilation => {
  14. compilation.hooks.afterOptimizeChunks.tap(
  15. "FlagInitialModulesAsUsedPlugin",
  16. chunks => {
  17. for (const chunk of chunks) {
  18. if (!chunk.isOnlyInitial()) {
  19. return;
  20. }
  21. for (const module of chunk.modulesIterable) {
  22. module.used = true;
  23. module.usedExports = true;
  24. module.addReason(null, null, this.explanation);
  25. }
  26. }
  27. }
  28. );
  29. }
  30. );
  31. }
  32. }
  33. module.exports = FlagInitialModulesAsUsedPlugin;