-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
zod > yup? #6
Comments
Looks really great, but one downside is that it doesn't work if the SvelteKit project doesn't use typescript: |
To be honest with you I had never of Zod. I've only used Yup and Superstruct. But I see it's quite popular with 2.4k stars. It seems a similar logic to what I did for @felte/validator-yup could be done for this 🤔. Why doesn't it work with a JS SvelteKit project? Is the distributable not bundled into JS? |
Corrrect, seems to be distributed as typescript. If I create a new SvelteKit project using typescript, it'd probably work. I wish the author published it to NPM as JS. I'll close this because there isn't really an action item here. Given Zod only works with typescript, yup is still a better general recommendation. |
Despite the error message, it turns out that Zod uses a JS entry point. I confirmed with the dev. The issue is apparently Vite attempting to import the wrong file: I'll follow up if I get Zod working, to see how much Kb size it saves over Yup. |
Since the changes between Zod and Yup aren't that drastic, I've added a validator package for Zod. I'll update the docs site in a bit. Thanks a lot for your interest in Felte! |
Fantastic! Thanks! Can't wait to try it in SvelteKit when Vite fixes the import issue. |
Update: Must install zod as a Size comparison: Felte, yup, & @felte/validator-yup imported:
.svelte/output/client/_app/pages/contact.svelte-f4df8f52.js 77.59kb / brotli: 20.89kb
Felte, yup, & @felte/validator-zod:
.svelte/output/client/_app/pages/demo/contact.svelte-fa381adb.js 56.93kb / brotli: 13.47kb Savings of ~20kb (7.42kb brotli) for a similar API. TBD if more can be saved using zod differently. The above used |
Installing as a devDependency for it to work seems to be a common solution for Vite dependency related errors. I should read more on Vite's docs to understand why. Thanks a lot for your research! I'll make sure to add a note about that in the docs. |
To check the production build size consequence of using yup (with DOM reporter), I built 3 ways:
Yup adds >200% to Felte's size. After exploring bundlephobia, I found zod.
What do you think about zod?
The text was updated successfully, but these errors were encountered: