WebWorkerHotUpdateChunkTemplatePlugin.js
1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";
const { ConcatSource } = require("webpack-sources");
class WebWorkerHotUpdateChunkTemplatePlugin {
apply(hotUpdateChunkTemplate) {
hotUpdateChunkTemplate.hooks.render.tap(
"WebWorkerHotUpdateChunkTemplatePlugin",
(modulesSource, modules, removedModules, hash, id) => {
const hotUpdateFunction =
hotUpdateChunkTemplate.outputOptions.hotUpdateFunction;
const globalObject = hotUpdateChunkTemplate.outputOptions.globalObject;
const source = new ConcatSource();
source.add(
`${globalObject}[${JSON.stringify(
hotUpdateFunction
)}](${JSON.stringify(id)},`
);
source.add(modulesSource);
source.add(")");
return source;
}
);
hotUpdateChunkTemplate.hooks.hash.tap(
"WebWorkerHotUpdateChunkTemplatePlugin",
hash => {
hash.update("WebWorkerHotUpdateChunkTemplatePlugin");
hash.update("3");
hash.update(
hotUpdateChunkTemplate.outputOptions.hotUpdateFunction + ""
);
hash.update(hotUpdateChunkTemplate.outputOptions.globalObject + "");
}
);
}
}
module.exports = WebWorkerHotUpdateChunkTemplatePlugin;