You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FetchCompileWasmTemplatePlugin.js 827B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const WasmMainTemplatePlugin = require("../wasm/WasmMainTemplatePlugin");
  7. class FetchCompileWasmTemplatePlugin {
  8. constructor(options) {
  9. this.options = options || {};
  10. }
  11. apply(compiler) {
  12. compiler.hooks.thisCompilation.tap(
  13. "FetchCompileWasmTemplatePlugin",
  14. compilation => {
  15. const mainTemplate = compilation.mainTemplate;
  16. const generateLoadBinaryCode = path =>
  17. `fetch(${mainTemplate.requireFn}.p + ${path})`;
  18. const plugin = new WasmMainTemplatePlugin(
  19. Object.assign(
  20. {
  21. generateLoadBinaryCode,
  22. supportsStreaming: true
  23. },
  24. this.options
  25. )
  26. );
  27. plugin.apply(mainTemplate);
  28. }
  29. );
  30. }
  31. }
  32. module.exports = FetchCompileWasmTemplatePlugin;