Reduce library size [Question] [Enhancement]
See original GitHub issueAt first — thank you for this awesome project.
Recently I debug my bundle and recognise that zod is almost the same as react-dom library and it’s 114kb non gziped code. I use latest version of zod 3.1.0.
Used named import of all zod, but also tried something like import { string } from 'zod'
with the same result
import { z } from 'zod';
export const linkShema = z.object({
title: z.string(),
link: z.string(),
});
Is it possible to remove at least unused parts of code from my bundle, because 100+ kb it’s a lot.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:9
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Reduce library size · Issue #81 · ipfs/go-ds-s3 - GitHub
For comparison the Java S3 client is ~3mb. Is there any way to reduce this by stripping out unused dependencies? Or just in......
Read more >c++ reduce library size by excluding unnecessary functions ...
You probably should first try to set up your compilation to minimize size. And the answer to your question depends a lot on...
Read more >how to reduce library size? - Unity Answers
The problem is when i created an empty android project with only camera in it, the apk size is about 14mb. When i...
Read more >Reduce library size in Final Cut Pro - Apple Community
Reduce library size in Final Cut Pro. I am not even sure if I am using Libraries, Events and Projects correctly but I...
Read more >Reduce your app size - Android Developers
Reduce resource count and size · Remove unused resources · Minimize resource use from libraries · Native animated image decoding · Support only...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Like @scotttrinh said, there’s a lot of circular dependencies where the base class is dependent on its own subclasses. This is necessary to add convenience methods like
.and
,.or
,.array
, etc. So Zod is structurally incompatible with treesplitting to some extent.I added minification to the Rollup config which seems to have decreased the size of
index.mjs
by 50kb (50% reduction).More manageable when gzipped and/or minified:
looking at the output, I’m not sure what else we could do: it’s pretty much just the output of
tsc
here. I don’t think it’s common practice for TypeScript libraries to do any minifying or anything, so I think this ends up falling on you as a consumer to minimize the impact of the library on your bundle. As it is, there is little that can be shaken out ofzod
, I think, since most of the “weight” is in the parser which is the part that does all of the real work. I’m no tree-shaking expert, though, so if anyone else can weigh in (no pun intended), I’d be interested to hear a more experienced take on this!