-
Notifications
You must be signed in to change notification settings - Fork 787
Conversation
00fa9be
to
f3da910
Compare
@benjamn as noted in the code removed,
This should be unnecessary with tree shaking. Aside from the conveniences of browser vs server indexes, file specific paths should be a thing of the past and we should be able to confidently use an index to generate the rollup bundle and have dead code eliminated in the application bundling phase.
👍
I'm not sure this makes sense. The key distinction here: let's not conflate a rollup bundle size produced with the size of the library in an application bundled with a modern tool like webpack or parcel that eliminates dead code. While perhaps there is an argument for different entry points for server vs browser, I do not understand going further down this path (file-specific imports, more split modules) when it should have a zero impact on app bundling over the current approach. With that said, things like prod vs dev bundles and #2677 can definitely help. |
WOW - my error. We are only producing umd for consumption - which appears to be the root cause of this. We need to configure our rollup to be producing an es module to aid in dead code elimination. Some examples:
We definitely need to be shipping an es/esm variant otherwise we are stuck with a non-shakeable (or poorly shakeable depending on the tool) umd. |
I can add this in my PR / make a seperate one for that if needed? We are offering the index.js as a module or is this not sufficient, because afaik it should be enough. |
@JoviDeCroock definitely separate. |
Right, I would have thought it was sufficient that the |
Afaik the tsc compiled bundle suffices for ESM, ESM is just ecmascript module syntax. Some packages give an .mjs there now but that isn't doable in frontend. I think it's safe to say it's meant to be an ES bundle and not ESM Maybe it should be es6 target in tsconfig that's still a question i'm playing with. |
My error once again, I saw the lack of target in the So this issue is about optimizing bundle size - is there a reason to focus on the umd bundle size? Is anyone focused on bundle size in their app using a umd build? If so why? perhaps I'm too far down my own path to understand what the problem we are attempting to solve. One thing I am sure of - we need a I would think we could provide |
I have been giving this some thought and for the |
Agreed @JoviDeCroock, just like I PR'd in apollo-client apollographql/apollo-client#4261:
The umd bundle is legacy and helps with putting your finger on the pulse of bundlesize (though not a foolproof indicator as we have discussed). Users concerned with tree shaking should ensure they are using the targeted |
I was wondering, now we are creating a seperate bundle for the umd libraries, can't this be solved with the |
Looks like there could be a few different ways to tackle this, one would be using the same index inputs and have multiple outputs (just makes the config more DRY):
Or the multiple inputs with pattern named outputs:
Definitely plenty of good/new options there. |
Is it possible to try out this PR, eg. is it published anywhere? It would be interesting to see if the esm bundle would allow some tree shaking. |
I'd also love to see this being tried out. Been reading some things about webpack being not that good at treeshaking bundles but leaving that to the tersers dead code elimination. If we can get it tested before we do a real publish we could still alter the course for that matter. |
Use our own flowRight-like function instead of using lodash.flowright. In addition to being smaller, this implementation does not require using CommonJS require to import a separate package.
This reduces the minified size of lib/react-apollo.umd.js from 28074B to 22773B (18.9%). The minified+gzip size drops from 6930B to 6451B (6.9%). The gzip percentage is smaller because there was some repetition between the multiple declarations of the __extends function, and gzip is good at compressing long repeated substrings.
* chore: optimize build time * fix: remove comments * tests: revert transforms * fix tests * remove babel key from pkg.json * chore: apply pr remarks * chore: undo all and add esm bundle with potential todo * remove unused babel plugins * cjs * some optimizations * add question * chore: follow pr * ignore rpt_cache
@JoviDeCroock @Pajn @rosskevin I'm hoping this prerelease helps with testing the changes in PR #2661.
63a83ab
to
f0c395b
Compare
According to BundlePhobia, version |
Why does it indicate 2.4.0 as tree-shakeable, the UMD build provided there should not be tree shakeable as far as I know. Also will use the bundle size version in my production application, that way we can see if there are any unforseen consequences. |
I wonder if that just means there's an ESM |
This shaves a tiny amount of bundle size, but more importantly it implements shallowEqual using TypeScript, and avoids one of the few remaining uses of require.
a21216d
to
b72dfd6
Compare
Does anyone have an SSR application using react-apollo. To test the new bundle-size build? Because I don't know how node reacts to the new pkg.json entries. |
Something that comes in my mind when thinking about reducing bundlesize is maybe implementing our render props/hoc/... with a hook. That way we get the advantage of exposing a hook AND our components can be reduced to only functions. This reduces the transpiling overhead of classes needing to be added. Just throwing it out there because well I can see as to why you could be opposed to this idea (supporting more react versions) |
So that will be interesting....
I'm already on render callbacks but will switch to hooks when they are ready. Is there an official roadmap for that now that hooks have been merged in react and will be released next? |
probably very soon since I just saw the PR about the changelog etc... So yes, I don't mind working on it I've already implemented quite a few hooks libraries, I just don't know if this is something apollo needs right now since it will probably be a major release. Will safe a massive amount of bundle size though. Also needs to be looked at if ssr has compat (I assume so by now) |
why is the module field in package.json pointing to a ts-file? IMHO rollup should produce ES modules and this field should point there. |
This is the case in master but not in 2.5.0-bundle-size.0 |
ah ok i see. but the tsconfig.json still transpiles to target:es5 which doesn't produce ES modules |
It does, it literally sais "es", it is just a transpiled down version of es6. No library transpiles to es6 in their module field. This would imply very long builds since your node modules should be transpiled to support all browsers |
Similar in spirit to apollographql/apollo-link#959 This inlining was first introduced in PR #2661 with the following commit: de2b5fc At the time, inlining made sense because TypeScript was injecting copies of the __extends, __rest, etc. helpers into every module that used them. Depending on the tslib package seemed undesirable because the available bundle size measurement tools (e.g. bundlephobia.com) mistakenly counted the entire tslib package against react-apollo, without acknowledging the possibility of sharing that package between multiple Apollo packages. It seemed safer to inline only the helpers we needed at the top of lib/react-apollo.esm.js. Now that we have a more holistic way to measure bundle sizes (#2839), and react-apollo works better with tree-shaking tools (#2659, #2661, #2677), we know that overall application bundle sizes benefit from sharing a single copy of the tslib helper package, even if no tree-shaking is happening. Of course, with tree-shaking, that one copy of the tslib package can be shrunk to contain just the helpers that are actually used.
Part of issue #2743, whose description previously appeared here.