Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

ChunkTemplate.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const { Tapable, SyncWaterfallHook, SyncHook } = require("tapable");
  7. /** @typedef {import("./ModuleTemplate")} ModuleTemplate */
  8. /** @typedef {import("./Chunk")} Chunk */
  9. /** @typedef {import("./Module")} Module} */
  10. /** @typedef {import("./Dependency").DependencyTemplate} DependencyTemplate} */
  11. /** @typedef {import("./util/createHash").Hash} Hash} */
  12. /**
  13. * @typedef {Object} RenderManifestOptions
  14. * @property {Chunk} chunk the chunk used to render
  15. * @property {string} hash
  16. * @property {string} fullHash
  17. * @property {TODO} outputOptions
  18. * @property {{javascript: ModuleTemplate, webassembly: ModuleTemplate}} moduleTemplates
  19. * @property {Map<TODO, TODO>} dependencyTemplates
  20. */
  21. module.exports = class ChunkTemplate extends Tapable {
  22. constructor(outputOptions) {
  23. super();
  24. this.outputOptions = outputOptions || {};
  25. this.hooks = {
  26. /** @type {SyncWaterfallHook<TODO[], RenderManifestOptions>} */
  27. renderManifest: new SyncWaterfallHook(["result", "options"]),
  28. modules: new SyncWaterfallHook([
  29. "source",
  30. "chunk",
  31. "moduleTemplate",
  32. "dependencyTemplates"
  33. ]),
  34. render: new SyncWaterfallHook([
  35. "source",
  36. "chunk",
  37. "moduleTemplate",
  38. "dependencyTemplates"
  39. ]),
  40. renderWithEntry: new SyncWaterfallHook(["source", "chunk"]),
  41. hash: new SyncHook(["hash"]),
  42. hashForChunk: new SyncHook(["hash", "chunk"])
  43. };
  44. }
  45. /**
  46. *
  47. * @param {RenderManifestOptions} options render manifest options
  48. * @returns {TODO[]} returns render manifest
  49. */
  50. getRenderManifest(options) {
  51. const result = [];
  52. this.hooks.renderManifest.call(result, options);
  53. return result;
  54. }
  55. /**
  56. * Updates hash with information from this template
  57. * @param {Hash} hash the hash to update
  58. * @returns {void}
  59. */
  60. updateHash(hash) {
  61. hash.update("ChunkTemplate");
  62. hash.update("2");
  63. this.hooks.hash.call(hash);
  64. }
  65. /**
  66. * TODO webpack 5: remove moduleTemplate and dependencyTemplates
  67. * Updates hash with chunk-specific information from this template
  68. * @param {Hash} hash the hash to update
  69. * @param {Chunk} chunk the chunk
  70. * @param {ModuleTemplate} moduleTemplate ModuleTemplate instance for render
  71. * @param {Map<Function, DependencyTemplate>} dependencyTemplates dependency templates
  72. * @returns {void}
  73. */
  74. updateHashForChunk(hash, chunk, moduleTemplate, dependencyTemplates) {
  75. this.updateHash(hash);
  76. this.hooks.hashForChunk.call(hash, chunk);
  77. }
  78. };