我用Emscripten把c函数编译生成hello.js和hello.wasm两个文件,可以在page/index.js里面require使用,但是在worker中使用就会遇到问题:
官网文档中说worker不能加载其目录以外的文件,实测也的确如此:
const hello_debug=require('../pages/index/hello.js')
报错:
thirdScriptError
worker uncaught third Error
module "pages/index/hello.js" is not defined
Error: module "pages/index/hello.js" is not defined
同时:
"在 Worker 内使用 WXWebAssembly 时,.wasm 文件需要放置在 worker 目录外,因为 worker 目录只会打包 .js 文件,非 .js 文件会被忽略"
我将胶水js放在worker目录下,wasm文件放在pages下,
const hello_debug=require('./hello.js')
报错:
thirdScriptError
worker uncaught third Error
module "pages/index/hello.js" is not defined
Error: module "pages/index/hello.js" is not defined
请问该如何在worker中加载webassembly的胶水js文件呢?这个报错原因是啥呢,谢谢!
胶水js放在worker目录下,wasm文件放在worker目录外,这个用法没问题。
具体原因得看看代码,可以通过代码片段功能展示一下代码: https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html
https://developers.weixin.qq.com/s/HbOu51mC7rvc
目前我可以用指令emcc hello.cc -s STANDALONE_WASM -o hellonew.wasm的形式生存不包含胶水js的wasm文件并在worker中调用。
但是如果普通的emcc hello.cc -o hello_glue.js,生成的wasm和胶水js在导入的时候会报错,如代码片段所示,请问该如何修改才能在小程序中使用呢?(能在普通的web中使用)。
谢谢!
请问能否分享基于WXWebAssembly的可在worker中用的最简胶水js呢?网上之前的代码大多基于改版之前的WebAssembly,目前小程序不支持了.
具体的情况我在这个提问中提出了:
https://developers.weixin.qq.com/community/develop/doc/000ca895518d6870211df985c56000
万分感谢!
我想问一下,你编译出来运行Wasm卡不卡,我这里很卡,不知道为什么,谢谢,很急