2013-06-19 19:49:57 +08:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
2018-07-30 23:08:51 +08:00
|
|
|
|
2017-01-13 04:38:38 +08:00
|
|
|
"use strict";
|
2013-06-19 19:49:57 +08:00
|
|
|
|
2018-06-26 14:27:44 +08:00
|
|
|
const { SyncWaterfallHook, SyncHook } = require("tapable");
|
2018-07-30 23:08:51 +08:00
|
|
|
const HotUpdateChunk = require("./HotUpdateChunk");
|
|
|
|
const Template = require("./Template");
|
2013-06-19 19:49:57 +08:00
|
|
|
|
2018-06-26 14:27:44 +08:00
|
|
|
module.exports = class HotUpdateChunkTemplate {
|
2017-01-13 04:38:38 +08:00
|
|
|
constructor(outputOptions) {
|
2017-12-07 16:42:33 +08:00
|
|
|
this.outputOptions = outputOptions || {};
|
2017-11-29 01:43:01 +08:00
|
|
|
this.hooks = {
|
2018-02-25 09:00:20 +08:00
|
|
|
modules: new SyncWaterfallHook([
|
|
|
|
"source",
|
|
|
|
"modules",
|
|
|
|
"removedModules",
|
|
|
|
"moduleTemplate",
|
|
|
|
"dependencyTemplates"
|
|
|
|
]),
|
|
|
|
render: new SyncWaterfallHook([
|
|
|
|
"source",
|
|
|
|
"modules",
|
|
|
|
"removedModules",
|
|
|
|
"hash",
|
|
|
|
"id",
|
|
|
|
"moduleTemplate",
|
|
|
|
"dependencyTemplates"
|
|
|
|
]),
|
|
|
|
hash: new SyncHook(["hash"])
|
2017-11-29 01:43:01 +08:00
|
|
|
};
|
2017-01-13 04:38:38 +08:00
|
|
|
}
|
2013-06-19 19:49:57 +08:00
|
|
|
|
2018-02-25 09:00:20 +08:00
|
|
|
render(
|
|
|
|
id,
|
|
|
|
modules,
|
|
|
|
removedModules,
|
|
|
|
hash,
|
|
|
|
moduleTemplate,
|
|
|
|
dependencyTemplates
|
|
|
|
) {
|
2018-04-12 17:04:49 +08:00
|
|
|
const hotUpdateChunk = new HotUpdateChunk();
|
2017-04-21 16:05:56 +08:00
|
|
|
hotUpdateChunk.id = id;
|
|
|
|
hotUpdateChunk.setModules(modules);
|
|
|
|
hotUpdateChunk.removedModules = removedModules;
|
2018-02-25 09:00:20 +08:00
|
|
|
const modulesSource = Template.renderChunkModules(
|
|
|
|
hotUpdateChunk,
|
2018-03-28 22:19:15 +08:00
|
|
|
m => typeof m.source === "function",
|
2018-02-25 09:00:20 +08:00
|
|
|
moduleTemplate,
|
|
|
|
dependencyTemplates
|
|
|
|
);
|
|
|
|
const core = this.hooks.modules.call(
|
|
|
|
modulesSource,
|
|
|
|
modules,
|
|
|
|
removedModules,
|
|
|
|
moduleTemplate,
|
|
|
|
dependencyTemplates
|
|
|
|
);
|
|
|
|
const source = this.hooks.render.call(
|
|
|
|
core,
|
|
|
|
modules,
|
|
|
|
removedModules,
|
|
|
|
hash,
|
|
|
|
id,
|
|
|
|
moduleTemplate,
|
|
|
|
dependencyTemplates
|
|
|
|
);
|
2017-01-13 04:38:38 +08:00
|
|
|
return source;
|
|
|
|
}
|
2016-05-20 13:39:36 +08:00
|
|
|
|
2017-01-13 04:38:38 +08:00
|
|
|
updateHash(hash) {
|
|
|
|
hash.update("HotUpdateChunkTemplate");
|
|
|
|
hash.update("1");
|
2017-11-29 01:43:01 +08:00
|
|
|
this.hooks.hash.call(hash);
|
2017-01-13 04:38:38 +08:00
|
|
|
}
|
2015-07-08 20:39:02 +08:00
|
|
|
};
|