MCPcopy
hub / github.com/webpack/webpack / apply

Method apply

lib/wasm/EnableWasmLoadingPlugin.js:84–157  ·  view source on GitHub ↗

* Enables the requested wasm loading backend once and applies the * environment-specific plugins that provide its parser, generator, and * runtime support. * @param {Compiler} compiler the compiler instance * @returns {void}

(compiler)

Source from the content-addressed store, hash-verified

82 * @returns {void}
83 */
84 apply(compiler) {
85 const { type } = this;
86
87 // Only enable once
88 const enabled = getEnabledTypes(compiler);
89 if (enabled.has(type)) return;
90 enabled.add(type);
91
92 if (typeof type === "string") {
93 switch (type) {
94 case "fetch": {
95 if (compiler.options.experiments.syncWebAssembly) {
96 const FetchCompileWasmPlugin = require("../web/FetchCompileWasmPlugin");
97
98 new FetchCompileWasmPlugin({
99 mangleImports: compiler.options.optimization.mangleWasmImports
100 }).apply(compiler);
101 }
102
103 if (compiler.options.experiments.asyncWebAssembly) {
104 const FetchCompileAsyncWasmPlugin = require("../web/FetchCompileAsyncWasmPlugin");
105
106 new FetchCompileAsyncWasmPlugin().apply(compiler);
107 }
108
109 break;
110 }
111 case "async-node": {
112 if (compiler.options.experiments.syncWebAssembly) {
113 const ReadFileCompileWasmPlugin = require("../node/ReadFileCompileWasmPlugin");
114
115 new ReadFileCompileWasmPlugin({
116 mangleImports: compiler.options.optimization.mangleWasmImports,
117 import:
118 compiler.options.output.module &&
119 compiler.options.output.environment.dynamicImport
120 }).apply(compiler);
121 }
122
123 if (compiler.options.experiments.asyncWebAssembly) {
124 const ReadFileCompileAsyncWasmPlugin = require("../node/ReadFileCompileAsyncWasmPlugin");
125
126 new ReadFileCompileAsyncWasmPlugin({
127 import:
128 compiler.options.output.module &&
129 compiler.options.output.environment.dynamicImport
130 }).apply(compiler);
131 }
132
133 break;
134 }
135 case "universal": {
136 if (compiler.options.experiments.syncWebAssembly) {
137 throw new Error(
138 "Universal wasm loading type is only supported by asynchronous web assembly."
139 );
140 }
141

Callers

nothing calls this directly

Calls 5

getEnabledTypesFunction · 0.70
applyMethod · 0.65
requireFunction · 0.50
hasMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected