source: trip-planner-front/node_modules/webpack/lib/web/FetchCompileAsyncWasmPlugin.js@ 6c1585f

Last change on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[6a3a178]1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const RuntimeGlobals = require("../RuntimeGlobals");
9const AsyncWasmChunkLoadingRuntimeModule = require("../wasm-async/AsyncWasmChunkLoadingRuntimeModule");
10
11/** @typedef {import("../Compiler")} Compiler */
12
13class FetchCompileAsyncWasmPlugin {
14 /**
15 * Apply the plugin
16 * @param {Compiler} compiler the compiler instance
17 * @returns {void}
18 */
19 apply(compiler) {
20 compiler.hooks.thisCompilation.tap(
21 "FetchCompileAsyncWasmPlugin",
22 compilation => {
23 const globalWasmLoading = compilation.outputOptions.wasmLoading;
24 const isEnabledForChunk = chunk => {
25 const options = chunk.getEntryOptions();
26 const wasmLoading =
27 options && options.wasmLoading !== undefined
28 ? options.wasmLoading
29 : globalWasmLoading;
30 return wasmLoading === "fetch";
31 };
32 const generateLoadBinaryCode = path =>
33 `fetch(${RuntimeGlobals.publicPath} + ${path})`;
34
35 compilation.hooks.runtimeRequirementInTree
36 .for(RuntimeGlobals.instantiateWasm)
37 .tap("FetchCompileAsyncWasmPlugin", (chunk, set) => {
38 if (!isEnabledForChunk(chunk)) return;
39 const chunkGraph = compilation.chunkGraph;
40 if (
41 !chunkGraph.hasModuleInGraph(
42 chunk,
43 m => m.type === "webassembly/async"
44 )
45 ) {
46 return;
47 }
48 set.add(RuntimeGlobals.publicPath);
49 compilation.addRuntimeModule(
50 chunk,
51 new AsyncWasmChunkLoadingRuntimeModule({
52 generateLoadBinaryCode,
53 supportsStreaming: true
54 })
55 );
56 });
57 }
58 );
59 }
60}
61
62module.exports = FetchCompileAsyncWasmPlugin;
Note: See TracBrowser for help on using the repository browser.