-
Notifications
You must be signed in to change notification settings - Fork 143
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
Separate ES6 module build + WASM only build #263
Comments
Sure, having smaller files can only be a good thing! And having separate builds would be great as well. As you said, most browsers support WebAssembly these days (notable exceptions being IE and browser extensions), so it's about time to get rid of the JS version if applicable. And your help would be more than welcome! |
I only use crypto_box_seal, I believe the reduction in JavaScript size will be significant. Where can I help you with this? |
Would appreciate having build options for WASM only, JS only, and WASM w/ JS fallback. The JS builds are still useful for browser extensions that can't readily support WASM without making some compromises. |
This is a great idea. Are there any updates on this? |
@jedisct1 would be glad to help but it's quite hard to understand how do you compile it right now. Maybe I could give you some basic explanation how i.e. rollup works? Modern bundlers (rollup/vite/pacel) have problems with libsodium, it's frustrating. |
In order to compile it, emscripten needs to be installed. Then, the
It's compiled twice by that script:
First to Javascript and then to WebAssembly. In that file, you can also see how the |
@jedisct1 thanks, already playing around! |
Any update for this issue? |
Now that tweetsodium is pointing people to this library I tried to migrate one of my github actions but since I'm targeting esm as my output I end up with this error when I try to run it:
I'm bundling with ncc and the issue seems to go back to webpack (ref vercel/ncc#749), but there doesn't seem to be a workaround for this currently aside from this library publishing an esm version. |
I would also love to see this in libsodium. It's our biggest dependency right now. |
No, seriously, we need ESM support. |
Anyone up to make this happen? Would be huge leap forward for the community 👀 |
WIP #337 |
When using libsodium in your project in combination with a bundler like Webpack, you can use all sorts of optimization techniques such as tree shaking. This is only possible for ES6 modules (I believe this is also the case for other bundles such as Rollup). The problem is that the current build is not bundled as an ES6 module. You can do a seperate ES6 build by adding a seperate entry point for modules in package.json:
In combination with this:
which is needed to indicate we don't do any special things on import.
I would like to help to make the needed changes, as I believe this will make a BIG impact on the package size in most projects. Because the bundler will be able to remove lots of unused code. But for this to work we need 1. to build via emscriptend with ES6 modules and 2. change the wrapper.
Would you accept this kind of change to the project and do you have any additional remarks and tips where to start?
Other semi related question:
As I understand correctly, both the legacy asm.js and WASM build are combined in libsodium.js. Wouldn't it make sense to create separate builds? Some applications maybe won't require support for non-modern browsers. Plus, in combination with a bundler it might be possible to only load the needed build at runtime (and if we can make the libsodium-wrappers smaller, this will be a great combination for a lot of projects).
The text was updated successfully, but these errors were encountered: