UNPKG

827 BJavaScriptView Raw
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5"use strict";
6
7const WasmMainTemplatePlugin = require("../wasm/WasmMainTemplatePlugin");
8
9class 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
37module.exports = FetchCompileWasmTemplatePlugin;