webpack/lib/ChunkTemplate.js

44 lines
1.2 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
2017-12-07 16:42:33 +08:00
const Tapable = require("tapable").Tapable;
2017-11-29 01:43:01 +08:00
const SyncWaterfallHook = require("tapable").SyncWaterfallHook;
const SyncHook = require("tapable").SyncHook;
2013-03-26 23:54:41 +08:00
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"]),
2017-11-29 01:43:01 +08:00
modules: new SyncWaterfallHook(["source", "chunk", "moduleTemplate", "dependencyTemplates"]),
render: new SyncWaterfallHook(["source", "chunk", "moduleTemplate", "dependencyTemplates"]),
renderWithEntry: new SyncWaterfallHook(["source", "chunk"]),
hash: new SyncHook(["hash"]),
hashForChunk: new SyncHook(["hash", "chunk"]),
};
}
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);
}
};