| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-28 01:02:02 +08:00
										 |  |  | const WasmMainTemplatePlugin = require("../wasm/WasmMainTemplatePlugin"); | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | class FetchCompileWasmTemplatePlugin { | 
					
						
							| 
									
										
										
										
											2018-06-06 05:38:29 +08:00
										 |  |  | 	constructor(options) { | 
					
						
							|  |  |  | 		this.options = options || {}; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 	apply(compiler) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		compiler.hooks.thisCompilation.tap( | 
					
						
							|  |  |  | 			"FetchCompileWasmTemplatePlugin", | 
					
						
							|  |  |  | 			compilation => { | 
					
						
							| 
									
										
										
										
											2018-04-28 14:53:30 +08:00
										 |  |  | 				const mainTemplate = compilation.mainTemplate; | 
					
						
							| 
									
										
										
										
											2018-04-28 01:02:02 +08:00
										 |  |  | 				const generateLoadBinaryCode = path => | 
					
						
							|  |  |  | 					`fetch(${mainTemplate.requireFn}.p + ${path})`; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-06 05:38:29 +08:00
										 |  |  | 				const plugin = new WasmMainTemplatePlugin( | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 					compilation.moduleGraph, | 
					
						
							| 
									
										
										
										
											2018-06-06 05:38:29 +08:00
										 |  |  | 					Object.assign( | 
					
						
							|  |  |  | 						{ | 
					
						
							|  |  |  | 							generateLoadBinaryCode, | 
					
						
							|  |  |  | 							supportsStreaming: true | 
					
						
							|  |  |  | 						}, | 
					
						
							|  |  |  | 						this.options | 
					
						
							|  |  |  | 					) | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2018-04-30 14:35:06 +08:00
										 |  |  | 				plugin.apply(mainTemplate); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = FetchCompileWasmTemplatePlugin; |