纱线和WASM模块链接由于纱线缓存而行不通
我在这里有一个非常简单的应用程序,其中index.html简单地导入index.js where:
index.js
import * as wasm from "wasm";
wasm.greet();
lib.rs
mod utils;
use wasm_bindgen::prelude::*;
#[cfg(feature = "wee_alloc")]
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
#[wasm_bindgen]
extern { fn alert(s: &str); }
#[wasm_bindgen]
pub fn greet() { alert("Wasm is running haha!"); }
package.json
...
"dependencies": {
"wasm": "portal:../pkg"
},
...
现在,这是我的问题:
- 当我使用
时,当我使用
“ file:.. ../ pkg” 在package.json中,一切都有效,但是如果 我使用wasm-pak包进行更改并重新编译,它不会更新。 即使运行
纱线安装
也不会更新。我能得到的唯一方法 要显示的更改是通过运行纱线安装-Check-files
,但是 安装需要时间,这很痛苦。 - 当我使用
“门户:../ pkg”
中的package.json中,我在./index.js模块中找到错误错误:错误:无法解析: “ ....
。这不是我所期望的。 - 当我使用
“链接:../ pkg”
一切都按计划工作,我不必每次编译时都能运行纱线安装
以查看更改。这太好了,我真正想要的。
但是,当我在此处阅读协议时 https://yarnpkg.com/features/protocols 如果package.json
存在于我的../ pkg
文件夹中,则门户网站只有该门户将遵循依赖项。就我而言,确实如此,我希望那里有进一步的依赖关系。那么我该如何才能开始工作呢?为什么链接正常工作现在不起作用?
I have a very simple app here where index.html simply imports index.js where:
index.js
import * as wasm from "wasm";
wasm.greet();
lib.rs
mod utils;
use wasm_bindgen::prelude::*;
#[cfg(feature = "wee_alloc")]
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
#[wasm_bindgen]
extern { fn alert(s: &str); }
#[wasm_bindgen]
pub fn greet() { alert("Wasm is running haha!"); }
package.json
...
"dependencies": {
"wasm": "portal:../pkg"
},
...
Now, here is my issue:
- When I use
"file:../pkg"
in package.json, everything works, but if
I make a change and recompile using wasm-pack it does not update.
Even runningyarn install
will not update. The only way I can get
changes to show is by runningyarn install --check-files
but then
the install takes time and it's quite painful. - When I use
"portal:../pkg"
in package.json instead, I get an errorERROR in ./index.js Module not found: Error: Can't resolve "wasm" ....
. This is not what I expect. - When I use
"link:../pkg"
everything works as planned, and I do not have to runyarn install
every-time I compile to see the changes. This is great and what I really want.
Yet, when I read protocols here https://yarnpkg.com/features/protocols the difference between link and portal is only that portal will follow dependencies if package.json
exists in my ../pkg
folder. In my case, it does, and I expect to have further dependencies there. So how can I get portal to work? And why is it not working now when link is working?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论