Open gkaemmer opened 5 years ago
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Removed the stale label and pinned because it's important and I'll look into it later
Just updated a bunch of 0x libraries to their latest versions and ended up with 7-8 copies of lodash,
we can fix by aliasing lodash
in webpack config but still a funky default.
Also, +1 on removing ethers as a dependency if possible :). It's 100kb gzipped, which adds a pretty significant portion of the download/parse time
Just wanted to chime in and say that this is indeed an important issue for many @0x/subproviders
consumers :)
Thanks for chiming @NoahZinsmeister. As a first step, we're going to move the GanacheSubprovider
out of this package since it's adds a ton to the bundle size, but most devs using this package don't use it.
@dekz can you post an updated bundlesize analysis once we remove it? Then we can see what other low-hanging fruit exists.
here's what it's looking like over here (we use mainly asset-swapper and some utils)
~5MB parsed ~800kb gzipped
Much wow. Very lodash
Hey guys! Was just going through our bundle size and came upon some (relatively) low-hanging bundle fruit.
(This issue is specifically about
@0x/subproviders
, but could probably be generalized to some other packages)Expected Behavior
When I run:
I should not end up with dependencies such as
eth-lightwallet
, andweb3
as a result.Current Behavior
When I run:
I do end up with
eth-lightwallet
,web3
,bip39
, among others as a result, growing my bundle size by an unnecessary 800kB (grows gzip bundle by ~150kB).Possible Solution
We've been using this workaround:
but obviously that's a bit brittle, and could change on an update.
I'd suggest making your packages tree-shakable, which (I believe) you can do with the following steps:
index.es6.js
in addition to theindex.js
andindex.d.ts
files. This file should containimport
andexport
statements instead ofexports.blah = require("blah")
. This is probably the trickiest step, and requires some special webpack config I think."module": "lib/src/index.es6.js"
topackage.json
so that a user's webpack can locate the special ES6 module."sideEffects": false
topackage.json
to tell webpack that it is safe to tree shake this module.Steps to Reproduce (for bugs)
In an empty project, create an
index.js
file:Compare the bundle size to that of
index2.js
:When they are the same, 🎉we're tree shaking! But now they are quite different 😢
Context
Was just trying to optimize our bundle size and remove some extraneous packages that seemed unused.
Your Environment
@0x/subproviders
Also, relatedly
import blah from "lodash/blah"
instead ofimport * as _ from "lodash"
! All of the 0x package seem to drag the entirelodash.min.js
into the bundle, most of which is unnecessary.ethers
everywhere? It's a really big dependency, and it seems like 0x only uses the ABI-encoding functionality from it.Thank you so much! These really are some of the best ethereum libraries out there, and we love them very much. Let me know if I can help in any way.