twilio-node icon indicating copy to clipboard operation
twilio-node copied to clipboard

Any possibility of reducing bundle size?

Open etc-tiago opened this issue 3 years ago • 7 comments

Today the entire package is over 13 mb. I'm using webpack to merge the code into a single file to run on AWS Lambda and about 96% of the package is from twilio.

One of the possibilities is to make the package more modular. AWS did this with the SDK and the result is very significant.

When using only S3, in version 2, it compiled about 69 mb. With version 3, only 3.9 mb.

Any chance of this happening with this twilio package?

etc-tiago avatar Jan 22 '22 05:01 etc-tiago

This issue has been added to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog.

beebzz avatar Jan 27 '22 00:01 beebzz

+1

VigneshMurugan avatar Feb 06 '22 07:02 VigneshMurugan

+1

imthatcarlos avatar Feb 15 '22 16:02 imthatcarlos

+1

for instance, change axios for built in fetch in NodeJS, if fetch isn't provided by the env, let user polyfill it themself with either undici, node-fetch or other

jimmywarting avatar Aug 27 '22 20:08 jimmywarting

+1

luisgrases avatar Dec 28 '22 20:12 luisgrases

Screen Shot 2023-01-06 at 5 56 02 AM

Solution: I spun up webpack, set it to target node, and terser-packed twilio-sdk into a single file (2mb) command to run npm run pack:analyze that produces an html

code can be found here: https://github.com/mariomui/twilio-node/tree/smaller-build

Observations: a) lodash isn't used at all but is still sizable. b) using (originally) tsc produces a 13mb lib c) using babel-loader(before minify) : 5mb , applying terser(after minify with base options): 2 mb d) If each function was in its own package (lerna/turborepo style) but requires gradual dev-time and maintainer buy-in. A terser pack-in seems to be the quick interim solution. d) heavy testing is required to see if this compressed package works. (although i don't see why it shouldnt') e) axios is a tiny dep in the great scheme of things.

Summary: I added 7 or 8 webpack + babel dev dependencies in order to minify it down. Not sure if we should do that. Turbopack and esbuild/rollup was considered but I was more familiar with webpack and its analyzer tools. Turbopack was also missing documentation on its minifying capabilities.

Prolly need a discussion on whether or not minifying it for lambdas is a good stop gap measure.

mariomui avatar Jan 06 '23 15:01 mariomui

Hey folks, we've recently released version 4.0.0 of twilio-node which introduces a ~30% reduction in bundle size. Community support is also welcome for any further contributions or propositions to reduce bundle size.

beebzz avatar Jan 26 '23 16:01 beebzz