Getting Started
Installation
Install the plugin:
bash
npm add zod@latest
npm add -D unplugin-valypebash
yarn add zod@latest
yarn add -D unplugin-valypebash
pnpm add zod@latest
pnpm add -D unplugin-valypebash
bun add zod@latest
bun add -D unplugin-valypezod's version should be
3.25.0at least, but we recommend using zod v4 for the best experience, because valype generates zod v4 schema
Configuration
Add the plugin to your build tool configuration:
Vite
ts
// vite.config.ts
import valype from 'unplugin-valype/vite'
export default defineConfig({
plugins: [
valype({ /* options */ }),
],
})Rollup
ts
// rollup.config.js
import valype from 'unplugin-valype/rollup'
export default {
plugins: [
valype({ /* options */ }),
],
}Webpack
ts
// webpack.config.js
module.exports = {
plugins: [
require('unplugin-valype/webpack')({ /* options */ })
]
}Nuxt
ts
// nuxt.config.js
export default defineNuxtConfig({
modules: [
['unplugin-valype/nuxt', { /* options */ }],
],
})Vue CLI
ts
// vue.config.js
module.exports = {
configureWebpack: {
plugins: [
require('unplugin-valype/webpack')({ /* options */ }),
],
},
}esbuild
ts
// esbuild.config.js
import { build } from 'esbuild'
import valype from 'unplugin-valype/esbuild'
build({
plugins: [valype()],
})Usage
- Define your types (use
.valype.tsextension):
typescript
// user.valype.ts
export interface User {
name: string
age: number
}- Use the generated validator:
typescript
import { validateUser } from './user.valype'
const issues = validateUser(data) // Returns ZodIssue[] or undefined
if (issues) {
// Handle validation errors
}For IDE/editor integration (VSCode extension, TypeScript plugin, etc.), see Editor & IDE Integration.
Validator Signature
unplugin-valype generates validators for types exported from *.valype.ts files:
typescript
export declare function validateSome(data: unknown): ZodIssue[] | undefined- Returns
undefinedwhen validation passes - Returns
ZodIssue[]with error details when validation fails
Note: You typically don't need to use
valypepackage directly, just use the generated validators.