serverPluginWasm.js 620 B

123456789101112131415161718
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.wasmPlugin = void 0;
  4. const utils_1 = require("../utils");
  5. exports.wasmPlugin = ({ app }) => {
  6. app.use((ctx, next) => {
  7. if (ctx.path.endsWith('.wasm') && utils_1.isImportRequest(ctx)) {
  8. ctx.type = 'js';
  9. ctx.body = `export default (opts = {}) => {
  10. return WebAssembly.instantiateStreaming(fetch(${JSON.stringify(ctx.path)}), opts)
  11. .then(obj => obj.instance.exports)
  12. }`;
  13. return;
  14. }
  15. return next();
  16. });
  17. };
  18. //# sourceMappingURL=serverPluginWasm.js.map