Skip to content

Separate ES6 module build + WASM only build #263

@SimonBackx

Description

@SimonBackx

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:

{
  "module": "./esm/dist/index.js"
}

In combination with this:

{
  "sideEffects": false
}

which is needed to indicate we don't do any special things on import.

A "side effect" is defined as code that performs a special behavior when imported, other than exposing one or more exports. An example of this are polyfills, which affect the global scope and usually do not provide an export.

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions