source: trip-planner-front/node_modules/webpack/lib/web/FetchCompileWasmPlugin.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.8 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 WasmChunkLoadingRuntimeModule = require("../wasm-sync/WasmChunkLoadingRuntimeModule");
10
11/** @typedef {import("../Compiler")} Compiler */
12
13// TODO webpack 6 remove
14
15class FetchCompileWasmPlugin {
16 constructor(options) {
17 this.options = options || {};
18 }
19
20 /**
21 * Apply the plugin
22 * @param {Compiler} compiler the compiler instance
23 * @returns {void}
24 */
25 apply(compiler) {
26 compiler.hooks.thisCompilation.tap(
27 "FetchCompileWasmPlugin",
28 compilation => {
29 const globalWasmLoading = compilation.outputOptions.wasmLoading;
30 const isEnabledForChunk = chunk => {
31 const options = chunk.getEntryOptions();
32 const wasmLoading =
33 options && options.wasmLoading !== undefined
34 ? options.wasmLoading
35 : globalWasmLoading;
36 return wasmLoading === "fetch";
37 };
38 const generateLoadBinaryCode = path =>
39 `fetch(${RuntimeGlobals.publicPath} + ${path})`;
40
41 compilation.hooks.runtimeRequirementInTree
42 .for(RuntimeGlobals.ensureChunkHandlers)
43 .tap("FetchCompileWasmPlugin", (chunk, set) => {
44 if (!isEnabledForChunk(chunk)) return;
45 const chunkGraph = compilation.chunkGraph;
46 if (
47 !chunkGraph.hasModuleInGraph(
48 chunk,
49 m => m.type === "webassembly/sync"
50 )
51 ) {
52 return;
53 }
54 set.add(RuntimeGlobals.moduleCache);
55 set.add(RuntimeGlobals.publicPath);
56 compilation.addRuntimeModule(
57 chunk,
58 new WasmChunkLoadingRuntimeModule({
59 generateLoadBinaryCode,
60 supportsStreaming: true,
61 mangleImports: this.options.mangleImports
62 })
63 );
64 });
65 }
66 );
67 }
68}
69
70module.exports = FetchCompileWasmPlugin;
Note: See TracBrowser for help on using the repository browser.