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