-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to import WASM files in certain frameworks #198
Comments
I don't really understand why it doesn't Just Work with the default Webpack settings: Webpack understands I'm not completely against an optional parameter to In other news, I hate hate hate the javascript ecosystem. How is this not a 100% solved problem yet? We seem to have spent more time on this project fighting Webpack and trying to so solve other packaging problems than actually writing code. |
@richvdh thanks for your quick response! I'm not an expert on how builders works, but I know that Angular does some kind of magic when building to maintain consistency, either you're using Webpack, Esbuild or Vite. if(environment.name === 'development'){
this.worker = new Worker(new URL('../utils/workers/myworker.worker', import.meta.url),
{name: 'worker', type: 'module'}
)
} else {
this.worker = new Worker(new URL('../utils/workers/myworker.worker', 'https://mypage.com')
{name: 'worker', type: 'module'}
)
} was being transpiled as: if(environment.name === 'development'){
this.worker = new Worker(new URL('worker-F4AB9Z', import.meta.url), // <--- this changed
{name: 'worker', type: 'module'}
)
} else {
this.worker = new Worker(new URL('../utils/workers/myworker.worker', 'https://mypage.com') // <--- but this doesn't
{name: 'worker', type: 'module'}
)
}
I can't agree more. In fact, nowadays there are more and more bundlers out there and they keep adding their own rules, making it really hard to maintain consistency for libraries that needs to import wasm or use web workers. |
Hi, the hardcoded URL in
index.mjs
makes it really hard to load the wasm file in certain framework. This can be changed with a few lines of code.As an example, I'm trying to implement a matrix client with e2e Encryption in Angular.
Angular can be used with Webpack or Esbuild, but they doesn't give you the ability to touch the webpack config, so we can't follow the webpack guide (if you're using it to bundle your Angular app).
The way to use Angular + Web Assembly is to expose
.wasm
as they are on the final build. You simply tell on theangular.json
file something like this:That basically means, on the final build, put the
matrix_sdk_crypto_wasm_bg.wasm
file under the/assets/
directory.And then you simply need to fetch doing something like this:
fetch("/assets/matrix_sdk_crypto_wasm_bg.wasm")
.. you can do the same if you want to use Angular's built-in HttpClient.Solution
Instead of hardcoding the URL like this
we could give the user the ability to send its own URL. This way, you could make this work with almost any framework (I think Vue and Svelte works the same way as Angular)
When testing my app, I manually edited the
index.mjs
to make it work without breaking backwards compatibility. I can replicate those changes if you want, But I don't know if I manually need to editindex.cjs
andindex.d.ts
by hand too or if those files gets automatically created.These are my changes if you wan't to replicate it and open a PR:
The text was updated successfully, but these errors were encountered: