From d5f14083061f2ce6a42313188443a42e30796320 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Tue, 31 Oct 2023 15:37:35 +0800 Subject: added make browserlist(autoprefixer) work fixed --- .../webpack/lib/web/FetchCompileAsyncWasmPlugin.js | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 node_modules/webpack/lib/web/FetchCompileAsyncWasmPlugin.js (limited to 'node_modules/webpack/lib/web/FetchCompileAsyncWasmPlugin.js') diff --git a/node_modules/webpack/lib/web/FetchCompileAsyncWasmPlugin.js b/node_modules/webpack/lib/web/FetchCompileAsyncWasmPlugin.js new file mode 100644 index 00000000..94aafc02 --- /dev/null +++ b/node_modules/webpack/lib/web/FetchCompileAsyncWasmPlugin.js @@ -0,0 +1,72 @@ +/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Tobias Koppers @sokra +*/ + +"use strict"; + +const { WEBASSEMBLY_MODULE_TYPE_ASYNC } = require("../ModuleTypeConstants"); +const RuntimeGlobals = require("../RuntimeGlobals"); +const AsyncWasmLoadingRuntimeModule = require("../wasm-async/AsyncWasmLoadingRuntimeModule"); + +/** @typedef {import("../Chunk")} Chunk */ +/** @typedef {import("../Compiler")} Compiler */ + +class FetchCompileAsyncWasmPlugin { + /** + * Apply the plugin + * @param {Compiler} compiler the compiler instance + * @returns {void} + */ + apply(compiler) { + compiler.hooks.thisCompilation.tap( + "FetchCompileAsyncWasmPlugin", + compilation => { + const globalWasmLoading = compilation.outputOptions.wasmLoading; + /** + * @param {Chunk} chunk chunk + * @returns {boolean} true, if wasm loading is enabled for the chunk + */ + const isEnabledForChunk = chunk => { + const options = chunk.getEntryOptions(); + const wasmLoading = + options && options.wasmLoading !== undefined + ? options.wasmLoading + : globalWasmLoading; + return wasmLoading === "fetch"; + }; + /** + * @param {string} path path to the wasm file + * @returns {string} code to load the wasm file + */ + const generateLoadBinaryCode = path => + `fetch(${RuntimeGlobals.publicPath} + ${path})`; + + compilation.hooks.runtimeRequirementInTree + .for(RuntimeGlobals.instantiateWasm) + .tap("FetchCompileAsyncWasmPlugin", (chunk, set) => { + if (!isEnabledForChunk(chunk)) return; + const chunkGraph = compilation.chunkGraph; + if ( + !chunkGraph.hasModuleInGraph( + chunk, + m => m.type === WEBASSEMBLY_MODULE_TYPE_ASYNC + ) + ) { + return; + } + set.add(RuntimeGlobals.publicPath); + compilation.addRuntimeModule( + chunk, + new AsyncWasmLoadingRuntimeModule({ + generateLoadBinaryCode, + supportsStreaming: true + }) + ); + }); + } + ); + } +} + +module.exports = FetchCompileAsyncWasmPlugin; -- cgit v1.2.3