2016-07-13 17:03:14 +08:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
2018-07-30 23:08:51 +08:00
|
|
|
|
2018-04-27 10:50:46 +08:00
|
|
|
"use strict";
|
|
|
|
|
2018-01-20 00:06:59 +08:00
|
|
|
const ChunkGroup = require("./ChunkGroup");
|
2018-04-30 15:21:42 +08:00
|
|
|
|
2018-07-09 20:48:28 +08:00
|
|
|
/** @typedef {import("./Chunk")} Chunk */
|
2018-04-30 15:22:07 +08:00
|
|
|
|
2018-04-25 05:27:25 +08:00
|
|
|
/**
|
2018-04-30 15:21:42 +08:00
|
|
|
* Entrypoint serves as an encapsulation primitive for chunks that are
|
2018-04-27 10:50:46 +08:00
|
|
|
* 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.
|
2018-04-25 05:27:25 +08:00
|
|
|
*/
|
2018-01-20 00:06:59 +08:00
|
|
|
class Entrypoint extends ChunkGroup {
|
2018-04-25 05:27:25 +08:00
|
|
|
/**
|
|
|
|
* Creates an instance of Entrypoint.
|
|
|
|
* @param {string} name the name of the entrypoint
|
|
|
|
*/
|
2016-12-29 14:58:26 +08:00
|
|
|
constructor(name) {
|
2018-01-20 00:06:59 +08:00
|
|
|
super(name);
|
2018-04-27 10:50:46 +08:00
|
|
|
/** @type {Chunk=} */
|
2018-01-11 00:08:56 +08:00
|
|
|
this.runtimeChunk = undefined;
|
2016-12-29 14:58:26 +08:00
|
|
|
}
|
|
|
|
|
2018-04-25 05:27:25 +08:00
|
|
|
/**
|
2018-04-30 15:21:42 +08:00
|
|
|
* isInitial will always return true for Entrypoint ChunkGroup.
|
2018-05-08 20:31:51 +08:00
|
|
|
* @returns {true} returns true as all entrypoints are initial ChunkGroups
|
2018-04-25 05:27:25 +08:00
|
|
|
*/
|
2018-01-20 00:06:59 +08:00
|
|
|
isInitial() {
|
|
|
|
return true;
|
2018-01-09 16:40:30 +08:00
|
|
|
}
|
|
|
|
|
2018-04-25 05:27:25 +08:00
|
|
|
/**
|
2018-04-30 15:21:42 +08:00
|
|
|
* Sets the runtimeChunk for an entrypoint.
|
2018-04-25 05:27:25 +08:00
|
|
|
* @param {Chunk} chunk the chunk being set as the runtime chunk.
|
2018-05-08 20:31:51 +08:00
|
|
|
* @returns {void}
|
2018-04-25 05:27:25 +08:00
|
|
|
*/
|
2018-01-11 00:08:56 +08:00
|
|
|
setRuntimeChunk(chunk) {
|
|
|
|
this.runtimeChunk = chunk;
|
|
|
|
}
|
|
|
|
|
2018-04-25 05:27:25 +08:00
|
|
|
/**
|
2018-04-30 15:21:42 +08:00
|
|
|
* Fetches the chunk reference containing the webpack bootstrap code
|
2018-05-08 20:31:51 +08:00
|
|
|
* @returns {Chunk} returns the runtime chunk or first chunk in `this.chunks`
|
2018-04-25 05:27:25 +08:00
|
|
|
*/
|
2017-04-23 00:59:15 +08:00
|
|
|
getRuntimeChunk() {
|
2018-01-11 00:08:56 +08:00
|
|
|
return this.runtimeChunk || this.chunks[0];
|
2017-04-23 00:59:15 +08:00
|
|
|
}
|
2016-11-29 08:38:17 +08:00
|
|
|
}
|
2016-12-29 14:58:26 +08:00
|
|
|
|
|
|
|
module.exports = Entrypoint;
|