Open slavik-chapelskyi opened 1 year ago
After investigation I have figured out that whole node-fetch package was replace with some small esbuild global.fetch polyfill
It is expected behavior. Why it doesn’t work for you?
After investigation I have figured out that whole node-fetch package was replace with some small esbuild global.fetch polyfill
It is expected behavior. Why it doesn’t work for you?
Because the package I'm checking bundle size is developed to be used in node projects only, and I'm interested in what the actual bundle size for node project not supporting fetch
In my world, there is no such thing as bundle size for Node.js project since you do not need bundlers for Node.js.
What do you mean for “bundle” in Node.js and why do you care about it’s size?
Our backend is build on top of AWS lambda, which have size limit of 50mb. So there is cold start problem when it comes to lamdas https://khalilstemmler.com/blogs/serverless/5-ways-to-manage-lambda-cold-starts/#Understanding-the-Cold-Start-Problem While bundle size is not primary first problem with cold starts, we are still care about reusable packages bundle size to make it each lambda as small as possible, to ensure smaller cold starts
I was able to fix this by replacing size-limit-preset-node-lib
with undocumented modifyEsbuildConfig
option and setting esbuild platform to node
.
Interesting problem :-/
Seems like you need to set custom esbuild config with a target to Node.js https://esbuild.github.io/api/#target
It will disable auto-polyfills.
Try to use config
option in Size Limi config.
I have tried to implement this tool in our monorepo containing only node specific packages or both browser/node compatible.
I'm facing issues using
@size-limit/preset-small-lib
preset of a node library, which is using node-fetch package. After running check the bundle was surprisingly small. After investigation I have figured out that wholenode-fetch
package was replace with some small esbuild global.fetch polyfill. That probably because it was build for web, not node platform. So I have switched preset to https://github.com/un-ts/size-limit/tree/main/packages/preset-node-lib and try to run bundle check with it. But it refuses to working withimport
option. I have also tried to change the CLI--save-bundler
option to check the output withoutimport
option, but it had the same error, so its impossible to properly check the bundle size for node packages.