Entrypoint.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const ChunkGroup = require("./ChunkGroup");
  7. /** @typedef {import("./Chunk")} Chunk */
  8. /**
  9. * Entrypoint serves as an encapsulation primitive for chunks that are
  10. * a part of a single ChunkGroup. They represent all bundles that need to be loaded for a
  11. * single instance of a page. Multi-page application architectures will typically yield multiple Entrypoint objects
  12. * inside of the compilation, whereas a Single Page App may only contain one with many lazy-loaded chunks.
  13. */
  14. class Entrypoint extends ChunkGroup {
  15. /**
  16. * Creates an instance of Entrypoint.
  17. * @param {string} name the name of the entrypoint
  18. */
  19. constructor(name) {
  20. super(name);
  21. /** @type {Chunk=} */
  22. this.runtimeChunk = undefined;
  23. }
  24. /**
  25. * isInitial will always return true for Entrypoint ChunkGroup.
  26. * @returns {true} returns true as all entrypoints are initial ChunkGroups
  27. */
  28. isInitial() {
  29. return true;
  30. }
  31. /**
  32. * Sets the runtimeChunk for an entrypoint.
  33. * @param {Chunk} chunk the chunk being set as the runtime chunk.
  34. * @returns {void}
  35. */
  36. setRuntimeChunk(chunk) {
  37. this.runtimeChunk = chunk;
  38. }
  39. /**
  40. * Fetches the chunk reference containing the webpack bootstrap code
  41. * @returns {Chunk} returns the runtime chunk or first chunk in `this.chunks`
  42. */
  43. getRuntimeChunk() {
  44. return this.runtimeChunk || this.chunks[0];
  45. }
  46. }
  47. module.exports = Entrypoint;