Skip to content

Commit c3c21d8

Browse files
committed
fix(Refactor createCompatibleModuleOutBundle to use async loading method WebAssembly.instantiateStreaming)
1 parent 5821611 commit c3c21d8

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/index.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,17 @@ function createCompatibleModuleInBundle(transpiledJs, transpiledWasm) {
6262

6363
function createCompatibleModuleOutBundle(publicPath) {
6464
return `
65-
var f=fetch(${publicPath}).then(function(response){
66-
return response.arrayBuffer();
67-
}).then(function(binary){
68-
var module = new WebAssembly.Module(binary);
69-
var instance = new WebAssembly.Instance(module, { env: { abort: function() {} } });
70-
return instance.exports;
71-
});
72-
module.exports =f;
73-
`;
65+
function createWebAssemblyModulePromise() {
66+
var p = WebAssembly.instantiateStreaming(
67+
fetch(${publicPath}),
68+
{ env: { abort: function() {} } }
69+
).then(function(module) {
70+
return module.instance.exports;
71+
});
72+
return p;
73+
}
74+
module.exports = createWebAssemblyModulePromise;
75+
`;
7476
}
7577
function mkDirsSync(dirname) {
7678
if (fs.existsSync(dirname)) {

0 commit comments

Comments
 (0)