1 |
|
2 |
|
3 |
|
4 |
|
5 | "use strict";
|
6 |
|
7 | const WasmMainTemplatePlugin = require("../wasm/WasmMainTemplatePlugin");
|
8 |
|
9 | class FetchCompileWasmTemplatePlugin {
|
10 | constructor(options) {
|
11 | this.options = options || {};
|
12 | }
|
13 |
|
14 | apply(compiler) {
|
15 | compiler.hooks.thisCompilation.tap(
|
16 | "FetchCompileWasmTemplatePlugin",
|
17 | compilation => {
|
18 | const mainTemplate = compilation.mainTemplate;
|
19 | const generateLoadBinaryCode = path =>
|
20 | `fetch(${mainTemplate.requireFn}.p + ${path})`;
|
21 |
|
22 | const plugin = new WasmMainTemplatePlugin(
|
23 | Object.assign(
|
24 | {
|
25 | generateLoadBinaryCode,
|
26 | supportsStreaming: true
|
27 | },
|
28 | this.options
|
29 | )
|
30 | );
|
31 | plugin.apply(mainTemplate);
|
32 | }
|
33 | );
|
34 | }
|
35 | }
|
36 |
|
37 | module.exports = FetchCompileWasmTemplatePlugin;
|