webpack/lib/ChunkTemplate.js

72 lines
1.7 KiB
JavaScript
Raw Normal View History

2013-03-26 23:54:41 +08:00
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";
2013-03-26 23:54:41 +08:00
const { Tapable, SyncWaterfallHook, SyncHook } = require("tapable");
2013-03-26 23:54:41 +08:00
/** @typedef {import("./ModuleTemplate")} ModuleTemplate */
/** @typedef {import("./Chunk")} Chunk */
/** @typedef {import("./Module")} Module} */
/** @typedef {import("crypto").Hash} Hash */
/**
* @typedef {Object} RenderManifestOptions
* @property {Chunk} chunk the chunk used to render
* @property {Hash} hash
* @property {string} fullHash
* @property {any} outputOptions
* @property {{javascript: ModuleTemplate, webassembly: ModuleTemplate}} moduleTemplates
* @property {Map} dependencyTemplates
*/
2017-12-07 16:42:33 +08:00
module.exports = class ChunkTemplate extends Tapable {
constructor(outputOptions) {
2017-12-07 16:42:33 +08:00
super();
this.outputOptions = outputOptions || {};
2017-11-29 01:43:01 +08:00
this.hooks = {
renderManifest: new SyncWaterfallHook(["result", "options"]),
2018-02-25 09:00:20 +08:00
modules: new SyncWaterfallHook([
"source",
"chunk",
"moduleTemplate",
"dependencyTemplates"
]),
render: new SyncWaterfallHook([
"source",
"chunk",
"moduleTemplate",
"dependencyTemplates"
]),
2017-11-29 01:43:01 +08:00
renderWithEntry: new SyncWaterfallHook(["source", "chunk"]),
hash: new SyncHook(["hash"]),
2018-02-25 09:00:20 +08:00
hashForChunk: new SyncHook(["hash", "chunk"])
2017-11-29 01:43:01 +08:00
};
}
/**
*
* @param {RenderManifestOptions} options render manifest options
* @returns {any[]} returns render manifest
*/
2017-10-30 20:56:57 +08:00
getRenderManifest(options) {
const result = [];
this.hooks.renderManifest.call(result, options);
2017-10-30 20:56:57 +08:00
return result;
}
updateHash(hash) {
hash.update("ChunkTemplate");
hash.update("2");
2017-11-29 01:43:01 +08:00
this.hooks.hash.call(hash);
}
updateHashForChunk(hash, chunk) {
this.updateHash(hash);
2017-11-29 01:43:01 +08:00
this.hooks.hashForChunk.call(hash, chunk);
}
};