Skip to content

Compile to ECMAScript Modules (ESM) instead of CommonJS #1004

@webmaster128

Description

@webmaster128

Right now, CosmJS produces CommonJS builds. This works well for all versions of Node.js as well as bundlers like Webpack in order to bundle for the web.

As mentioned in https://vuejsdevelopers.com/2019/02/04/vue-es-module-browser-build/ ("What benefit is there of using Vue as an ES module?"), there is little obvious benefit for switching from CommonJS to ESM since the consumers are either node.js apps or bundlers. However, there is hope that ESM helps optimizing bundle size through tree shaking because ESM can better do static analysis on what is used and what is not (https://webpack.js.org/guides/tree-shaking/). In #904 you see that right now web apps include a lot of unused code that is only needed for key storage.

Other libraries use bundlers to bundle ES modules for the web. This is not desired here as we don't have a single entry point and do not want to decide for that user what should be included in such a bundle.

Do we need CommonJS+ESM hybrid builds?

Does this reduce bundle size

Testing

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions