UNPKG

1.62 kBJavaScriptView Raw
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5"use strict";
6
7const Template = require("./Template");
8const HotUpdateChunk = require("./HotUpdateChunk");
9const { Tapable, SyncWaterfallHook, SyncHook } = require("tapable");
10
11module.exports = class HotUpdateChunkTemplate extends Tapable {
12 constructor(outputOptions) {
13 super();
14 this.outputOptions = outputOptions || {};
15 this.hooks = {
16 modules: new SyncWaterfallHook([
17 "source",
18 "modules",
19 "removedModules",
20 "moduleTemplate",
21 "dependencyTemplates"
22 ]),
23 render: new SyncWaterfallHook([
24 "source",
25 "modules",
26 "removedModules",
27 "hash",
28 "id",
29 "moduleTemplate",
30 "dependencyTemplates"
31 ]),
32 hash: new SyncHook(["hash"])
33 };
34 }
35
36 render(
37 id,
38 modules,
39 removedModules,
40 hash,
41 moduleTemplate,
42 dependencyTemplates
43 ) {
44 const hotUpdateChunk = new HotUpdateChunk();
45 hotUpdateChunk.id = id;
46 hotUpdateChunk.setModules(modules);
47 hotUpdateChunk.removedModules = removedModules;
48 const modulesSource = Template.renderChunkModules(
49 hotUpdateChunk,
50 m => typeof m.source === "function",
51 moduleTemplate,
52 dependencyTemplates
53 );
54 const core = this.hooks.modules.call(
55 modulesSource,
56 modules,
57 removedModules,
58 moduleTemplate,
59 dependencyTemplates
60 );
61 const source = this.hooks.render.call(
62 core,
63 modules,
64 removedModules,
65 hash,
66 id,
67 moduleTemplate,
68 dependencyTemplates
69 );
70 return source;
71 }
72
73 updateHash(hash) {
74 hash.update("HotUpdateChunkTemplate");
75 hash.update("1");
76 this.hooks.hash.call(hash);
77 }
78};