* Registers compilation hooks that parse and generate sync WebAssembly * modules, emit their binary assets, and report invalid placement in initial * chunks. * @param {Compiler} compiler the compiler instance * @returns {void}
(compiler)
| 60 | * @returns {void} |
| 61 | */ |
| 62 | apply(compiler) { |
| 63 | compiler.hooks.compilation.tap( |
| 64 | PLUGIN_NAME, |
| 65 | (compilation, { normalModuleFactory }) => { |
| 66 | compilation.dependencyFactories.set( |
| 67 | WebAssemblyImportDependency, |
| 68 | normalModuleFactory |
| 69 | ); |
| 70 | |
| 71 | compilation.dependencyFactories.set( |
| 72 | WebAssemblyExportImportedDependency, |
| 73 | normalModuleFactory |
| 74 | ); |
| 75 | |
| 76 | normalModuleFactory.hooks.createModuleClass |
| 77 | .for(WEBASSEMBLY_MODULE_TYPE_SYNC) |
| 78 | .tap(PLUGIN_NAME, (createData, _resolveData) => { |
| 79 | const SyncWasmModule = getSyncWasmModule(); |
| 80 | |
| 81 | return new SyncWasmModule(createData); |
| 82 | }); |
| 83 | |
| 84 | normalModuleFactory.hooks.createParser |
| 85 | .for(WEBASSEMBLY_MODULE_TYPE_SYNC) |
| 86 | .tap(PLUGIN_NAME, () => { |
| 87 | const WebAssemblyParser = getWebAssemblyParser(); |
| 88 | |
| 89 | return new WebAssemblyParser(); |
| 90 | }); |
| 91 | |
| 92 | normalModuleFactory.hooks.createGenerator |
| 93 | .for(WEBASSEMBLY_MODULE_TYPE_SYNC) |
| 94 | .tap(PLUGIN_NAME, () => { |
| 95 | const WebAssemblyJavascriptGenerator = |
| 96 | getWebAssemblyJavascriptGenerator(); |
| 97 | const WebAssemblyGenerator = getWebAssemblyGenerator(); |
| 98 | |
| 99 | return Generator.byType({ |
| 100 | [JAVASCRIPT_TYPE]: new WebAssemblyJavascriptGenerator(), |
| 101 | [WEBASSEMBLY_TYPE]: new WebAssemblyGenerator(this.options) |
| 102 | }); |
| 103 | }); |
| 104 | |
| 105 | compilation.hooks.renderManifest.tap(PLUGIN_NAME, (result, options) => { |
| 106 | const { chunkGraph } = compilation; |
| 107 | const { chunk, outputOptions, codeGenerationResults } = options; |
| 108 | |
| 109 | for (const module of chunkGraph.getOrderedChunkModulesIterable( |
| 110 | chunk, |
| 111 | compareModulesByFullName(compiler) |
| 112 | )) { |
| 113 | if (module.type === WEBASSEMBLY_MODULE_TYPE_SYNC) { |
| 114 | const filenameTemplate = outputOptions.webassemblyModuleFilename; |
| 115 | |
| 116 | result.push({ |
| 117 | render: () => |
| 118 | codeGenerationResults.getSource( |
| 119 | module, |
nothing calls this directly
no test coverage detected