a zip code crypto-currency system good for red ONLY

EnsureChunkConditionsPlugin.js 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. class EnsureChunkConditionsPlugin {
  7. apply(compiler) {
  8. compiler.plugin("compilation", (compilation) => {
  9. const triesMap = new Map();
  10. compilation.plugin(["optimize-chunks-basic", "optimize-extracted-chunks-basic"], (chunks) => {
  11. let changed = false;
  12. chunks.forEach((chunk) => {
  13. chunk.forEachModule((module) => {
  14. if(!module.chunkCondition) return;
  15. if(!module.chunkCondition(chunk)) {
  16. let usedChunks = triesMap.get(module);
  17. if(!usedChunks) triesMap.set(module, usedChunks = new Set());
  18. usedChunks.add(chunk);
  19. const newChunks = [];
  20. chunk.parents.forEach((parent) => {
  21. if(!usedChunks.has(parent)) {
  22. parent.addModule(module);
  23. module.addChunk(parent);
  24. newChunks.push(parent);
  25. }
  26. });
  27. module.rewriteChunkInReasons(chunk, newChunks);
  28. chunk.removeModule(module);
  29. changed = true;
  30. }
  31. });
  32. });
  33. if(changed) return true;
  34. });
  35. });
  36. }
  37. }
  38. module.exports = EnsureChunkConditionsPlugin;