babel-plugin-zod-hoist
v1.0.4
Published
Hoists Zod schema definitions to the top of the file.
Readme
Babel Plugin to Hoist Zod Schemas
Hoists Zod schema definitions to the top of the file.
This:
function getSchema() {
return z.object({ name: z.string() });
}Becomes this:
const _schema_94b7f = z.object({
name: z.string(),
});
function getSchema() {
return _schema_94b7f;
}Motivation
Initializing Zod schemas is expensive.
By hoisting the schema to the top of the file, we can avoid re-initializing the schema every time we use it.
Why Use This?
- Performance Boost: Prevents unnecessary re-initialization.
- Zero Mental Overhead: Write normal Zod code - the hoisting happens automatically.
- No Code Changes Required: Works with your existing codebase without modifications.
Installation
npm install --save-dev babel-plugin-zod-hoistUsage
Add the plugin to your Babel configuration:
{
"plugins": ["babel-plugin-zod-hoist"]
}