纱线和WASM模块链接由于纱线缓存而行不通

发布于 2025-01-30 11:53:37 字数 1323 浏览 2 评论 0原文

我在这里有一个非常简单的应用程序,其中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 running yarn install will not update. The only way I can get
    changes to show is by running yarn 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 error ERROR 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 run yarn 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文