Vite plugin to decouple Zod schemas from heavy dependencies
npm install @zod-codepen/vite-plugin> [!TIP]
> @zod-codepen/vite-plugin provides seamless Vite integration for Zod schema serialization. Automatically transform and optimize your schemas at build time. Visit our documentation site for complete setup guide and examples.
``bash`
npm install -D @zod-codepen/vite-plugin
`typescript
// vite.config.ts
import { defineConfig } from 'vite';
import zodCodepen from '@zod-codepen/vite-plugin';
export default defineConfig({
plugins: [
zodCodepen({
// Options
})
]
});
`
- 🚀 Build-time optimization - Transform schemas during build
- 🔧 Hot Module Replacement - Instant updates during development
- 📦 Tree-shaking friendly - Optimized bundle size
- 🎯 TypeScript support - Full type safety
- âš¡ Zero runtime overhead - All transformations at build time
`typescript
interface ZodCodepenOptions {
// Include patterns for transformation
include?: string | string[];
// Exclude patterns
exclude?: string | string[];
// Output format
format?: 'esm' | 'cjs';
// Enable source maps
sourcemap?: boolean;
}
`
`typescript
// schemas.ts
import { z } from 'zod';
export const UserSchema = z.object({
name: z.string(),
email: z.string().email(),
age: z.number().int().positive()
});
// With the plugin, this schema can be automatically serialized
// and optimized during build time
``
For detailed configuration options and advanced usage:
- Getting Started
- Basic Usage
- API Reference
- Interactive Playground
- Node.js ≥ 20
- Vite ≥ 5.0.0
- Zod ^3.0.0 or ^4.0.0
MPL-2.0 © CornWorld