felixmosh/unplugin-zod-to-mini(opens in a new tab)
Language: TypeScript
A build-time transformer that converts Zod schemas to use Zod/mini — a tree-shakable variant of Zod.
- stars
- 3
- watchers
- 0
- forks
- 0
- open issues
- 0
- Last updated
- 05/16/2026
Language: TypeScript
A build-time transformer that converts Zod schemas to use Zod/mini — a tree-shakable variant of Zod.
A build-time transformer that converts Zod schemas to use zod/mini — a tree-shakable variant of Zod.
Zod Mini is a tree-shakable variant of Zod. It implements the exact same functionality, but with a functional API instead of method chaining.
Full Zod adds significant bundle weight to your application. zod/mini provides the same runtime validation with a fraction of the size. Based on the simple example z.boolean().parse(true):
| Package | Bundle size (gzip) |
|---|---|
| Zod Mini | 2.12kb |
| Zod | 5.91kb |
For a more complex schema with objects (z.object({ a: z.string(), b: z.number(), c: z.boolean() })), the sizes are 4.0kb vs 13.1kb respectively.
This plugin automatically rewrites your Zod imports and transforms your schemas at build time, so you get the smaller bundle without changing your code.
In regular Zod, you use method chaining:
const mySchema = z.string().optional().nullable();
In Zod Mini, you use functions instead:
const mySchema = z.nullable(z.optional(z.string()));
For validation methods:
// regular Zod z.string().min(5).max(10).trim(); // Zod Mini z.string().check(z.minLength(5), z.maxLength(10), z.trim());
Use this plugin if you want to:
Skip this plugin if you:
In our testing with a ~250 endpoint Fastify service using input & output schema validations, converting from regular Zod to Zod Mini reduced memory consumption by ~20MB from cold boot.
zod to zod/mini importstring, number, boolean, object, array, enum, literal, optional, nullable, etc.min, max, email, minLength, maxLength, uuid, url, etc.transform, refine, pipe, brand, extend, omit, pickstrictObject, looseObject, partial, requirednpm install unplugin-zod-to-mini
// vite.config.ts import zodToMini from "unplugin-zod-to-mini/vite"; import { defineConfig } from "vite"; export default defineConfig({ plugins: [zodToMini()], });
// rollup.config.js import zodToMini from "unplugin-zod-to-mini/rollup"; export default { plugins: [zodToMini()], };
// webpack.config.js module.exports = { plugins: [require("unplugin-zod-to-mini/webpack")()], };
// nuxt.config.ts export default defineNuxtConfig({ modules: ["unplugin-zod-to-mini/nuxt"], });
// esbuild.config.js import { build } from "esbuild"; import zodToMini from "unplugin-zod-to-mini/esbuild"; build({ plugins: [zodToMini()], });
// rspack.config.js import zodToMini from "unplugin-zod-to-mini/rspack"; export default { plugins: [ zodToMini({ // options }), ], };
Before transformation:
import { z } from "zod"; const UserSchema = z.object({ name: z.string().min(2).max(50), email: z.email(), age: z.number().min(0).optional(), }); export type User = z.infer<typeof UserSchema>;
After transformation (build output):
import { z } from "zod/mini"; const UserSchema = z.object({ name: z.string().check(z.minLength(2), z.maxLength(50)), email: z.email(), age: z.optional(z.number().check(z.gte(0))), }); export type User = z.infer<typeof UserSchema>;
interface PluginOptions { // Enable source maps for debugging sourceMaps?: boolean; // default: true // Enable JSX support jsx?: boolean; // default: false }