You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.6 KiB

4 years ago
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const Template = require("./Template");
  7. const HotUpdateChunk = require("./HotUpdateChunk");
  8. const { Tapable, SyncWaterfallHook, SyncHook } = require("tapable");
  9. module.exports = class HotUpdateChunkTemplate extends Tapable {
  10. constructor(outputOptions) {
  11. super();
  12. this.outputOptions = outputOptions || {};
  13. this.hooks = {
  14. modules: new SyncWaterfallHook([
  15. "source",
  16. "modules",
  17. "removedModules",
  18. "moduleTemplate",
  19. "dependencyTemplates"
  20. ]),
  21. render: new SyncWaterfallHook([
  22. "source",
  23. "modules",
  24. "removedModules",
  25. "hash",
  26. "id",
  27. "moduleTemplate",
  28. "dependencyTemplates"
  29. ]),
  30. hash: new SyncHook(["hash"])
  31. };
  32. }
  33. render(
  34. id,
  35. modules,
  36. removedModules,
  37. hash,
  38. moduleTemplate,
  39. dependencyTemplates
  40. ) {
  41. const hotUpdateChunk = new HotUpdateChunk();
  42. hotUpdateChunk.id = id;
  43. hotUpdateChunk.setModules(modules);
  44. hotUpdateChunk.removedModules = removedModules;
  45. const modulesSource = Template.renderChunkModules(
  46. hotUpdateChunk,
  47. m => typeof m.source === "function",
  48. moduleTemplate,
  49. dependencyTemplates
  50. );
  51. const core = this.hooks.modules.call(
  52. modulesSource,
  53. modules,
  54. removedModules,
  55. moduleTemplate,
  56. dependencyTemplates
  57. );
  58. const source = this.hooks.render.call(
  59. core,
  60. modules,
  61. removedModules,
  62. hash,
  63. id,
  64. moduleTemplate,
  65. dependencyTemplates
  66. );
  67. return source;
  68. }
  69. updateHash(hash) {
  70. hash.update("HotUpdateChunkTemplate");
  71. hash.update("1");
  72. this.hooks.hash.call(hash);
  73. }
  74. };