ChunkTemplate.js 1.1KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const ConcatSource = require("webpack-sources").ConcatSource;
  7. const Template = require("./Template");
  8. module.exports = class ChunkTemplate extends Template {
  9. constructor(outputOptions) {
  10. super(outputOptions);
  11. }
  12. render(chunk, moduleTemplate, dependencyTemplates) {
  13. const moduleSources = this.renderChunkModules(chunk, moduleTemplate, dependencyTemplates);
  14. const core = this.applyPluginsWaterfall("modules", moduleSources, chunk, moduleTemplate, dependencyTemplates);
  15. let source = this.applyPluginsWaterfall("render", core, chunk, moduleTemplate, dependencyTemplates);
  16. if(chunk.hasEntryModule()) {
  17. source = this.applyPluginsWaterfall("render-with-entry", source, chunk);
  18. }
  19. chunk.rendered = true;
  20. return new ConcatSource(source, ";");
  21. }
  22. updateHash(hash) {
  23. hash.update("ChunkTemplate");
  24. hash.update("2");
  25. this.applyPlugins("hash", hash);
  26. }
  27. updateHashForChunk(hash, chunk) {
  28. this.updateHash(hash);
  29. this.applyPlugins("hash-for-chunk", hash, chunk);
  30. }
  31. };