Web3.js: Are multiple packages still needed?

Created on 8 Dec 2018  路  6Comments  路  Source: ChainSafe/web3.js

I'm getting up to date with the recent changes to this project, and read in @nivida's post that there will be different bundles of web3.js for different use-cases. This gave me some ideas that I'm sharing here.

My understanding is that web3 was modularized in many packages so users could pick the parts they need and avoid importing the entire lib, as it's really big. While node users also benefit from smaller packages, they are specially important for web development, and there's lots of tooling focused on that that could be leveraged.

Exporting an ESM-based version of web3 let users take advantage of bundlers' tree-shaking capabilities, resulting in small bundles (probably smaller than the current module-specific ones) without having to manage nor think about multiple packages. This may require some changes, but would also simplify the project, which could be once again a single package.

Note that this approach is becoming fairly standard in web development, and many of the most used libraries are adopting it. Some examples are: lodash, underscore and date-fns.

I haven't spent much time thinking about how big of a change this would be, or how much impact it would have on current users of the beta versions, but a quick look at web3 and web3-eth on npm reveals that the intermediate packages have very few direct users.

2.x Stale discussion enhancement

Most helpful comment

So the idea is to go back to from lerna monorepo with multiple packages to one package? I think one should create a new issue stating this Todo in a clear manner with a QA section and then reference this new issue here and close this one here.

I find that the lerna monorepo is not a good solution, only one package should be release (web3). I also would say that this issue should have the highest priority of all issues.

All 6 comments

Currently, most are using the web3.min.js file or they are bundling the dapp with webpack and the web3.js bundle will go up to 6.2Mb.
The next release should not have a minified web3 file where anything is included it will just have UMD, commonJS and ESM bundles for each package. It has to be disscused with @frozeman .

I think the described coming changes above will be the first step to a new structure of web3 but our focus is currently on the stability and maintainability of the code. All bigger changes of this lib will be after the stable release.

This doesn't mean that I agree with you.
I thought for example about a repository structure without seperate packages on npm like this:

core/
    methods
    subscriptions
    providers
    modules
    ...
eth/
   abi
   contract
   ...

But all changes like this have to be done after the stable release and also to be discussed with @frozeman. :-)

Hi @nivida, I understand that the focus is currently somewhere else, and I agree with that. I just wanted to initiate this discussion before 1.0.0 is released because a change in the direction I described is somewhat in conflict with releasing stable individual packages. Maintaining the single-package and individual-packages versions at the same time would be a lot of work.

So the idea is to go back to from lerna monorepo with multiple packages to one package? I think one should create a new issue stating this Todo in a clear manner with a QA section and then reference this new issue here and close this one here.

I find that the lerna monorepo is not a good solution, only one package should be release (web3). I also would say that this issue should have the highest priority of all issues.

Not important for 1.0. Too much work.

I think if we do this after the stable release then we could combine it with my namespace idea which will improve the bundle size and will also give us some better ways to handle different providers with one web3 instance.

Namespace idea: https://gist.github.com/nivida/c7c24723353c243e295dbff954d06b50

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions

Was this page helpful?
0 / 5 - 0 ratings