FlagIncludedChunksPlugin.js 982 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. class FlagIncludedChunksPlugin {
  7. apply(compiler) {
  8. compiler.plugin("compilation", (compilation) => {
  9. compilation.plugin("optimize-chunk-ids", (chunks) => {
  10. chunks.forEach((chunkA) => {
  11. chunks.forEach((chunkB) => {
  12. // as we iterate the same iterables twice
  13. // skip if we find ourselves
  14. if(chunkA === chunkB) return;
  15. // instead of swapping A and B just bail
  16. // as we loop twice the current A will be B and B then A
  17. if(chunkA.getNumberOfModules() < chunkB.getNumberOfModules()) return;
  18. if(chunkB.getNumberOfModules() === 0) return;
  19. // is chunkB in chunkA?
  20. for(const m of chunkB.modulesIterable) {
  21. if(!chunkA.containsModule(m)) return;
  22. }
  23. chunkA.ids.push(chunkB.id);
  24. });
  25. });
  26. });
  27. });
  28. }
  29. }
  30. module.exports = FlagIncludedChunksPlugin;