| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const RuntimeGlobals = require("../RuntimeGlobals"); | 
					
						
							| 
									
										
										
										
											2019-05-22 14:59:26 +08:00
										 |  |  | const WasmChunkLoadingRuntimeModule = require("../wasm/WasmChunkLoadingRuntimeModule"); | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** @typedef {import("../Compiler")} Compiler */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class FetchCompileWasmPlugin { | 
					
						
							|  |  |  | 	constructor(options) { | 
					
						
							|  |  |  | 		this.options = options || {}; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Compiler} compiler the compiler instance | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	apply(compiler) { | 
					
						
							|  |  |  | 		compiler.hooks.thisCompilation.tap( | 
					
						
							|  |  |  | 			"FetchCompileWasmPlugin", | 
					
						
							|  |  |  | 			compilation => { | 
					
						
							|  |  |  | 				const generateLoadBinaryCode = path => | 
					
						
							|  |  |  | 					`fetch(${RuntimeGlobals.publicPath} + ${path})`; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				compilation.hooks.runtimeRequirementInTree | 
					
						
							|  |  |  | 					.for(RuntimeGlobals.ensureChunkHandlers) | 
					
						
							|  |  |  | 					.tap("FetchCompileWasmPlugin", (chunk, set) => { | 
					
						
							|  |  |  | 						const chunkGraph = compilation.chunkGraph; | 
					
						
							|  |  |  | 						if ( | 
					
						
							| 
									
										
										
										
											2019-05-24 18:30:43 +08:00
										 |  |  | 							!chunkGraph.hasModuleInGraph( | 
					
						
							|  |  |  | 								chunk, | 
					
						
							| 
									
										
										
										
											2019-07-15 21:03:29 +08:00
										 |  |  | 								m => m.type === "webassembly/sync" | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 							) | 
					
						
							|  |  |  | 						) { | 
					
						
							|  |  |  | 							return; | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						set.add(RuntimeGlobals.moduleCache); | 
					
						
							|  |  |  | 						set.add(RuntimeGlobals.publicPath); | 
					
						
							|  |  |  | 						compilation.addRuntimeModule( | 
					
						
							|  |  |  | 							chunk, | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 							new WasmChunkLoadingRuntimeModule({ | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 								generateLoadBinaryCode, | 
					
						
							|  |  |  | 								supportsStreaming: true, | 
					
						
							|  |  |  | 								mangleImports: this.options.mangleImports | 
					
						
							|  |  |  | 							}) | 
					
						
							|  |  |  | 						); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = FetchCompileWasmPlugin; |