Skip to content

Commit

Permalink
chore: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-R44 committed Jan 21, 2025
1 parent d089daf commit 3bedb2a
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ No more CI to restart because you are missing an environment variable, or to rea
## Features
- Validate your environment variables at **build time only**. No runtime overhead
- Totally type-safe
- Support multiple validation librairies ( [Zod](https://zod.dev/), and [@poppinss/validator-lite](https://github.com/poppinss/validator-lite/) )
- Support [standard-schema](https://github.com/standard-schema/standard-schema), meaning you can use every libraries compatible with it ( Zod, Valibot, ArkType )
- Parsing, validation and transformation of your variables
- Custom rules and error messages

Expand Down Expand Up @@ -265,6 +265,39 @@ interface ImportMetaEnv extends ImportMetaEnvAugmented {
}
```

## Standard Schema

> [!WARNING]
> As long as standard-schema has not been published in 1.0.0, I will possibly make breaking changes to the API without major release.
[standard-schema](https://github.com/standard-schema/standard-schema) is basically an attempt to standardize the way we can use validation librairies. It means that you can use any library that is compatible with it. As the date of writing, Zod, Valibot, Arktype, ArriSchema are compatible.

Here is an example of how to use it with the plugin:

```ts
// Zod validation
import { defineConfig } from '@julr/vite-plugin-validate-env'
import { z } from 'zod'
import * as v from 'valibot'
import { type } from 'arktype'

export default defineConfig({
validator: 'standard', // Make sure to use 'standard' validator
schema: {
// Zod
VITE_ZOD_VARIABLE: z.string(),

// Valibot
VITE_VALIBOT_VARIABLE: v.string(),

// Arktype
VITE_ARKTYPE_VARIABLE: type.string(),
},
})
```

Make sure to upgrade your validation library to the latest version to ensure using a compatible version with standard-schema. For example, Zod minimum version is `3.24.0`.

## Forbid unknown variables

Since we rely on module augmentation to type `import.meta.env`, using unknown variables won’t trigger errors because the `ImportMetaEnv` interface from Vite includes a `[key: string]: string` signature.
Expand Down

0 comments on commit 3bedb2a

Please sign in to comment.