MergeDuplicateChunksPlugin.js 768 B

12345678910111213141516171819202122232425262728
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. class MergeDuplicateChunksPlugin {
  7. apply(compiler) {
  8. compiler.plugin("compilation", (compilation) => {
  9. compilation.plugin("optimize-chunks-basic", (chunks) => {
  10. const map = Object.create(null);
  11. chunks.slice().forEach((chunk) => {
  12. if(chunk.hasRuntime() || chunk.hasEntryModule()) return;
  13. const ident = chunk.getModulesIdent();
  14. const otherChunk = map[ident];
  15. if(otherChunk) {
  16. if(otherChunk.integrate(chunk, "duplicate"))
  17. chunks.splice(chunks.indexOf(chunk), 1);
  18. return;
  19. }
  20. map[ident] = chunk;
  21. });
  22. });
  23. });
  24. }
  25. }
  26. module.exports = MergeDuplicateChunksPlugin;