Entrypoint.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. * @param {Chunk} oldChunk chunk to be replaced
  48. * @param {Chunk} newChunk New chunkt that will be replaced
  49. * @returns {boolean} rerturns true for
  50. */
  51. replaceChunk(oldChunk, newChunk) {
  52. if (this.runtimeChunk === oldChunk) this.runtimeChunk = newChunk;
  53. return super.replaceChunk(oldChunk, newChunk);
  54. }
  55. }
  56. module.exports = Entrypoint;