1
|
/*
|
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
Author Tobias Koppers @sokra
|
4
|
*/
|
5
|
"use strict";
|
6
|
|
7
|
const { Tapable, SyncWaterfallHook, SyncHook } = require("tapable");
|
8
|
|
9
|
/** @typedef {import("./ModuleTemplate")} ModuleTemplate */
|
10
|
/** @typedef {import("./Chunk")} Chunk */
|
11
|
/** @typedef {import("./Module")} Module} */
|
12
|
/** @typedef {import("./Dependency").DependencyTemplate} DependencyTemplate} */
|
13
|
/** @typedef {import("./util/createHash").Hash} Hash} */
|
14
|
|
15
|
/**
|
16
|
* @typedef {Object} RenderManifestOptions
|
17
|
* @property {Chunk} chunk the chunk used to render
|
18
|
* @property {string} hash
|
19
|
* @property {string} fullHash
|
20
|
* @property {TODO} outputOptions
|
21
|
* @property {{javascript: ModuleTemplate, webassembly: ModuleTemplate}} moduleTemplates
|
22
|
* @property {Map<TODO, TODO>} dependencyTemplates
|
23
|
*/
|
24
|
|
25
|
module.exports = class ChunkTemplate extends Tapable {
|
26
|
constructor(outputOptions) {
|
27
|
super();
|
28
|
this.outputOptions = outputOptions || {};
|
29
|
this.hooks = {
|
30
|
/** @type {SyncWaterfallHook<TODO[], RenderManifestOptions>} */
|
31
|
renderManifest: new SyncWaterfallHook(["result", "options"]),
|
32
|
modules: new SyncWaterfallHook([
|
33
|
"source",
|
34
|
"chunk",
|
35
|
"moduleTemplate",
|
36
|
"dependencyTemplates"
|
37
|
]),
|
38
|
render: new SyncWaterfallHook([
|
39
|
"source",
|
40
|
"chunk",
|
41
|
"moduleTemplate",
|
42
|
"dependencyTemplates"
|
43
|
]),
|
44
|
renderWithEntry: new SyncWaterfallHook(["source", "chunk"]),
|
45
|
hash: new SyncHook(["hash"]),
|
46
|
hashForChunk: new SyncHook(["hash", "chunk"])
|
47
|
};
|
48
|
}
|
49
|
|
50
|
/**
|
51
|
*
|
52
|
* @param {RenderManifestOptions} options render manifest options
|
53
|
* @returns {TODO[]} returns render manifest
|
54
|
*/
|
55
|
getRenderManifest(options) {
|
56
|
const result = [];
|
57
|
|
58
|
this.hooks.renderManifest.call(result, options);
|
59
|
|
60
|
return result;
|
61
|
}
|
62
|
|
63
|
/**
|
64
|
* Updates hash with information from this template
|
65
|
* @param {Hash} hash the hash to update
|
66
|
* @returns {void}
|
67
|
*/
|
68
|
updateHash(hash) {
|
69
|
hash.update("ChunkTemplate");
|
70
|
hash.update("2");
|
71
|
this.hooks.hash.call(hash);
|
72
|
}
|
73
|
|
74
|
/**
|
75
|
* TODO webpack 5: remove moduleTemplate and dependencyTemplates
|
76
|
* Updates hash with chunk-specific information from this template
|
77
|
* @param {Hash} hash the hash to update
|
78
|
* @param {Chunk} chunk the chunk
|
79
|
* @param {ModuleTemplate} moduleTemplate ModuleTemplate instance for render
|
80
|
* @param {Map<Function, DependencyTemplate>} dependencyTemplates dependency templates
|
81
|
* @returns {void}
|
82
|
*/
|
83
|
updateHashForChunk(hash, chunk, moduleTemplate, dependencyTemplates) {
|
84
|
this.updateHash(hash);
|
85
|
this.hooks.hashForChunk.call(hash, chunk);
|
86
|
}
|
87
|
};
|