2017-07-13 28 views

回答

0

ChakraCore已经WebAssembly支持和节点chakracore自8.x中通过JavaScript支持它:如果你正在使用从WebAssembly 方法

WASM在节点ChakraCore支持JavaScript的。从这里使用basic.wasm,下面 代码工作与节点ChakraCore:

const fs = require('fs'); const buf = fs.readFileSync('basic.wasm') 

async function test() { 
    try { 
     const module = await WebAssembly.compile(buf); 
     const inst = new WebAssembly.Instance(module, {test: {foo: function(a){console.log(`foo called: ${a}`); return 2;}}}); 
     console.log(inst.exports.a(1)); 
    } catch (reason) { 
     console.log(`Failed: ${reason}`) 
    } } 

test(); 

https://github.com/sass/node-sass/pull/1777#discussion_r127280773

0

或者,您可以使用node-wasm加载您WASM文件,然后在您的节点JS的应用,这样做:

import loadWasm from 'node-wasm'; 

async function run() { 
    const {rust_function} = await loadWasm('/local/path/to/wasm'); 
    const result = rust_function(); 
    console.log(result); 
} 

run(); 

有一个完整的例子here在同一回购协议。祝你好运!