ajv-pack produces compact standalone validation modules from JSON schemas compiled with Ajv (v4.7.4+). Version 0.3.1 is the latest stable release. It reduces bundle size by excluding Ajv at runtime and avoids dynamic code evaluation (useful for CSP). Compared to alternatives like @exodus/schemasafe or is-my-json-valid, ajv-pack specifically works with Ajv-generated code and is designed for build-time pre-compilation. Key limitations: no support for custom compiled/validated keywords, custom formats, recursive references (except self-ref), or async schemas.
npm install ajv-packNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Compile a JSON schema with Ajv (sourceCode: true), generate standalone validation module, and save or require it.
Update Ajv to >=4.7.4 and ensure { sourceCode: true } is set.Avoid using custom formats with ajv-pack, or validate manually.
Simplify schemas to avoid circular references; use self-reference only.
Refactor custom keywords to inline or macro types.
Use sync-only schemas with ajv-pack.
const ajv = new Ajv({ sourceCode: true });Use import pack from 'ajv-pack' or set type: 'module' in package.json and use createRequire.
Run npm install ajv-pack