diff options
Diffstat (limited to 'node_modules/webpack/lib/Entrypoint.js')
-rw-r--r-- | node_modules/webpack/lib/Entrypoint.js | 97 |
1 files changed, 54 insertions, 43 deletions
diff --git a/node_modules/webpack/lib/Entrypoint.js b/node_modules/webpack/lib/Entrypoint.js index 04dc2084b..c67ff44ed 100644 --- a/node_modules/webpack/lib/Entrypoint.js +++ b/node_modules/webpack/lib/Entrypoint.js @@ -1,43 +1,54 @@ -/*
- MIT License http://www.opensource.org/licenses/mit-license.php
- Author Tobias Koppers @sokra
-*/
-"use strict";
-
-class Entrypoint {
- constructor(name) {
- this.name = name;
- this.chunks = [];
- }
-
- unshiftChunk(chunk) {
- this.chunks.unshift(chunk);
- chunk.entrypoints.push(this);
- }
-
- insertChunk(chunk, before) {
- const idx = this.chunks.indexOf(before);
- if(idx >= 0) {
- this.chunks.splice(idx, 0, chunk);
- } else {
- throw new Error("before chunk not found");
- }
- chunk.entrypoints.push(this);
- }
-
- getFiles() {
- const files = [];
-
- for(let chunkIdx = 0; chunkIdx < this.chunks.length; chunkIdx++) {
- for(let fileIdx = 0; fileIdx < this.chunks[chunkIdx].files.length; fileIdx++) {
- if(files.indexOf(this.chunks[chunkIdx].files[fileIdx]) === -1) {
- files.push(this.chunks[chunkIdx].files[fileIdx]);
- }
- }
- }
-
- return files;
- }
-}
-
-module.exports = Entrypoint;
+/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Tobias Koppers @sokra +*/ +"use strict"; + +const ChunkGroup = require("./ChunkGroup"); + +/** @typedef {import("./Chunk")} Chunk */ + +/** + * Entrypoint serves as an encapsulation primitive for chunks that are + * a part of a single ChunkGroup. They represent all bundles that need to be loaded for a + * single instance of a page. Multi-page application architectures will typically yield multiple Entrypoint objects + * inside of the compilation, whereas a Single Page App may only contain one with many lazy-loaded chunks. + */ +class Entrypoint extends ChunkGroup { + /** + * Creates an instance of Entrypoint. + * @param {string} name the name of the entrypoint + */ + constructor(name) { + super(name); + /** @type {Chunk=} */ + this.runtimeChunk = undefined; + } + + /** + * isInitial will always return true for Entrypoint ChunkGroup. + * @returns {true} returns true as all entrypoints are initial ChunkGroups + */ + isInitial() { + return true; + } + + /** + * Sets the runtimeChunk for an entrypoint. + * @param {Chunk} chunk the chunk being set as the runtime chunk. + * @returns {void} + */ + setRuntimeChunk(chunk) { + this.runtimeChunk = chunk; + } + + /** + * Fetches the chunk reference containing the webpack bootstrap code + * @returns {Chunk} returns the runtime chunk or first chunk in `this.chunks` + */ + getRuntimeChunk() { + return this.runtimeChunk || this.chunks[0]; + } +} + +module.exports = Entrypoint; |