Add an asset entry point #31
Copy link
Copy link
Open
Description
@pimterry , I are recently working on another kind of entry for the web environment of these packages with less "side-effects".
It is in asset.js with another export in package.json, the document is at asset.md, and an example is available at example/webpack-asset.
Do you think it is fine and can I open a PR for the new entry?
Originally posted by @myl7 in #18 (comment)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
pimterry commentedon Nov 28, 2023
Just pulling this out as a separate topic @myl7, to avoid confusing that thread too much.
Can you explain more about how this works, and exactly why it's useful?
Is there a good reason why we'd need to do this here, instead of fixing the target (or adding a new target) in the wasm-pack project itself?
I'd really like to avoid maintaining more and more complicated entrypoints if we can - it would be much better if wasm-pack could handle this properly. That's less maintenance for each of us on these packages, but would also make it much easier for everybody else building wasm packages elsewhere to do the same thing automatically.
oligamiq commentedon Jan 20, 2025
The asset entry should be like this, as in brotli-dec-wasm.
By doing the above, you can write code like this, which will greatly improve the development experience by allowing the vite side to manage the publication of the asset, etc.
Also, to use it with cloudflare workers, you must be able to specify the path, as per this documentation. In other words, you must be able to create a WebassemblyModule based on the path. The way to do so is to expose the init function.
#6
The code generated by wasm-pack is thought out in this regard, and if you do not want to wrap it on this side of the library, we recommend that you expose it as an
export.In the meantime, I will send out a pull request later as I want to develop with vite.
oligamiq commentedon Jan 20, 2025
#40
With the changes you see in this pull request, I am able to write code like this.
cloudflare docs:
https://developers.cloudflare.com/workers/runtime-apis/webassembly/javascript/#use-from-javascript
https://developers.cloudflare.com/workers/wrangler/bundling/#including-non-javascript-modules
Also, to use it with cloudflare workers, you must be able to specify the path, as per this documentation. In other words, you must be able to create a WebassemblyModule based on the path. The way to do so is to expose the init function.