2021-03-01 15:06:11 +08:00

18 lines
620 B
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.wasmPlugin = void 0;
const utils_1 = require("../utils");
exports.wasmPlugin = ({ app }) => {
app.use((ctx, next) => {
if (ctx.path.endsWith('.wasm') && utils_1.isImportRequest(ctx)) {
ctx.type = 'js';
ctx.body = `export default (opts = {}) => {
return WebAssembly.instantiateStreaming(fetch(${JSON.stringify(ctx.path)}), opts)
.then(obj => obj.instance.exports)
}`;
return;
}
return next();
});
};
//# sourceMappingURL=serverPluginWasm.js.map