Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Entrypoint.js 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 chunk that will be replaced with
  49. * @returns {boolean} returns true if the replacement was successful
  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;