twilio-node
twilio-node copied to clipboard
Any possibility of reducing bundle size?
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?
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.
+1
+1
+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
+1

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.
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.