Skip to content
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

Registering the wasm folder vs JavaScript bundlers #1259

Open
andy-wrks opened this issue Feb 9, 2025 · 2 comments
Open

Registering the wasm folder vs JavaScript bundlers #1259

andy-wrks opened this issue Feb 9, 2025 · 2 comments
Labels
enhancement New feature or request

Comments

@andy-wrks
Copy link

What is your idea?

Currently the wasm file is registered via a path:
...settings.wasm.path = wasmPath;

This is problematic when using bundlers, which usually rely on bundling specific files and resolving a file path (rather than a folder path).
For example, it's not possible to use the cache busting feature of esbuild with webifc.wasm. How this usually works: esbuild includes a hash in the file name when bundling the file to the "dist" folder. It then resolves the file path to the new file name, like dist/webifc-1f67a5.wasm
However, since webifc looks for a hard coded file name inside a folder, this cache-busting technique can't work.
(In the case of esbuild, cache busting is the default bevahiour and it has to be turned off manually. Then the file name has to be deleted from the resolved path to provide a folder path for webifc.)

So to make web-ifc more compatible with common bundling workflows, I'd suggest to register the wasm file rather than the folder. Since there's only one wasm file anyway, it shouldn't make much of a difference.

Thanks for taking this into consideration and thanks for providing this great library!

@andy-wrks andy-wrks added the enhancement New feature or request label Feb 9, 2025
@beachtom
Copy link
Collaborator

So we don't want to loose the ability for people to set the WASM path in the JS code, because quite a few fetch the wasm from CDN. There is also a different wasm in node - and a multi thread WASM that is used if the browser supports it. Can this deal with this situation?

@andy-wrks
Copy link
Author

Sorry, I wasn't aware that there are different wasm files for different use cases. Please ignore what I said about there being only 1 wasm file...

I can refer to the DuckDB WASM port, which looks to be in a similar situation. It features 2 wasm files, where one seems to be for legacy browser environments (if I understand correctly) and they have a routine for picking the appropriate wasm file. They have examples on how to use it via CDN, Webpack and Vite here:

https://duckdb.org/docs/clients/wasm/instantiation

I mentioned esbuild in my original post, but their Webpack and Vite examples follow the same principle: you explicitly import both wasm files, so both paths can later be resolved to wherever they are bundled. The rest of their boiler plate seems to be quite custom, like pairing the wasm files with the worker files and automating which one to use.

It's probably not worth getting a headache about this feature request. I thought it could make life easier for people using bundlers. A bundled webifc can definitely be brought to life by disabling cache-busting and an extra line of code to turn the resolved file path into a folder path. If you come to the conclusion that changing the current behaviour would negativerly affect other scenarios, then it is what it is :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants