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

Provide a nicer way to load the WASM #23

Closed
sindresorhus opened this issue Mar 11, 2023 · 4 comments · Fixed by #24
Closed

Provide a nicer way to load the WASM #23

sindresorhus opened this issue Mar 11, 2023 · 4 comments · Fixed by #24

Comments

@sindresorhus
Copy link

I don't see why it requires the boilerplate. This package could simply do the following internally: https://github.com/vadimdemedes/ink/pull/550/files#diff-71628bd9ca8b59e4cfa0d8ae58caf4e8d5072d71a34be7517b7876b27c415dff

I should be able to do this and be done:

import Yoga from 'yoga-wasm-web';

For custom loading of WASM, there could be an alternative sub-export or something, but the main export should be the nicest one.

@jeetiss
Copy link
Collaborator

jeetiss commented Mar 11, 2023

I created a yoga-wasm-web/auto sub-export that uses export conditions to detect the node/browser environment and load the wasm file.

I tested it with ink and it works fine with node but still not sure that it will work with webpack and browsers.

@sindresorhus does it solve the boilerplate problem for you?

@sindresorhus
Copy link
Author

sindresorhus commented Mar 11, 2023

Yes, that looks good. Thanks for doing that. I would personally have made auto the default though (but not up to me).

@sindresorhus
Copy link
Author

I tested it with ink and it works fine with node but still not sure that it will work with webpack and browsers.

It should work fine in any bundler that support export conditions, which I think Webpack 5 supports.

@shuding
Copy link
Owner

shuding commented Mar 12, 2023

When creating this lib, it was mainly used in CF Workers which has a special way to load WASM (https://blog.cloudflare.com/webassembly-on-cloudflare-workers) as well as Vercel's Edge Runtime (https://vercel.com/docs/concepts/functions/edge-functions/wasm#using-a-webassembly-file). And then there's the use case of using inside the browser and I wanted to prefetch the WASM file via a tag.

Because there're probably more runtimes out there I made it that way to make sure it's flexible enough.

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

Successfully merging a pull request may close this issue.

3 participants