@arkenv/vite-plugin 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +2 -2
- package/package.json +8 -5
package/README.md
CHANGED
|
@@ -1,3 +1,88 @@
|
|
|
1
1
|
# `@arkenv/vite-plugin`
|
|
2
2
|
|
|
3
3
|
A Vite plugin for using ArkEnv to validate environment variables at build time.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @arkenv/vite-plugin arkenv arktype
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quickstart
|
|
12
|
+
|
|
13
|
+
```typescript title="vite.config.ts"
|
|
14
|
+
import arkenv from "@arkenv/vite-plugin";
|
|
15
|
+
import { defineConfig } from "vite";
|
|
16
|
+
|
|
17
|
+
export default defineConfig({
|
|
18
|
+
plugins: [
|
|
19
|
+
arkenv({
|
|
20
|
+
VITE_API_URL: "string",
|
|
21
|
+
VITE_APP_NAME: "'MyApp' | 'TestApp'",
|
|
22
|
+
"VITE_DEBUG?": 'boolean = false'
|
|
23
|
+
}),
|
|
24
|
+
],
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Features
|
|
29
|
+
|
|
30
|
+
- 🔒 **Build-time validation**: Catch missing or invalid environment variables during build
|
|
31
|
+
- 🚀 **TypeScript support**: Full type inference for your environment variables
|
|
32
|
+
- 💪 **Powered by ArkType**: Leverage ArkType's powerful type system
|
|
33
|
+
- ⚡ **Zero runtime overhead**: Validation happens at build time only
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
The plugin validates environment variables that start with `VITE_` (Vite's convention for client-side environment variables). Define your schema in the plugin configuration:
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
arkenv({
|
|
41
|
+
// Required string
|
|
42
|
+
VITE_API_URL: "string",
|
|
43
|
+
|
|
44
|
+
// String literal union
|
|
45
|
+
VITE_NODE_ENV: "'development' | 'production' | 'test'",
|
|
46
|
+
|
|
47
|
+
// Optional with default
|
|
48
|
+
"VITE_DEBUG?": 'boolean = false',
|
|
49
|
+
|
|
50
|
+
// Array of strings
|
|
51
|
+
"VITE_ALLOWED_ORIGINS?": 'string[] = []'
|
|
52
|
+
})
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Environment Variables
|
|
56
|
+
|
|
57
|
+
Create a `.env` file in your project root:
|
|
58
|
+
|
|
59
|
+
```dotenv title=".env"
|
|
60
|
+
VITE_API_URL=https://api.example.com
|
|
61
|
+
VITE_NODE_ENV=development
|
|
62
|
+
VITE_DEBUG=true
|
|
63
|
+
VITE_ALLOWED_ORIGINS=http://localhost:3000,https://example.com
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## TypeScript Integration
|
|
67
|
+
|
|
68
|
+
The plugin automatically provides type information for `import.meta.env`:
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
// TypeScript knows the exact types!
|
|
72
|
+
console.log(import.meta.env.VITE_API_URL); // string
|
|
73
|
+
console.log(import.meta.env.VITE_NODE_ENV); // "development" | "production" | "test"
|
|
74
|
+
console.log(import.meta.env.VITE_DEBUG); // boolean
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Examples
|
|
78
|
+
|
|
79
|
+
See the [with-vite-react-ts example](https://github.com/yamcodes/arkenv/tree/main/examples/with-vite-react-ts) for a complete working setup.
|
|
80
|
+
|
|
81
|
+
## Documentation
|
|
82
|
+
|
|
83
|
+
For detailed documentation and more examples, visit the [ArkEnv documentation site](https://arkenv.js.org).
|
|
84
|
+
|
|
85
|
+
## Related
|
|
86
|
+
|
|
87
|
+
- [ArkEnv](https://github.com/yamcodes/arkenv) - The core library
|
|
88
|
+
- [ArkType](https://arktype.io/) - The underlying validator / type system
|
package/dist/index.cjs
CHANGED
|
@@ -28,6 +28,6 @@ var import_vite = require("vite");
|
|
|
28
28
|
var index_default = (options) => ({
|
|
29
29
|
name: "@arkenv/vite-plugin",
|
|
30
30
|
config(_config, { mode }) {
|
|
31
|
-
(0, import_arkenv.
|
|
31
|
+
(0, import_arkenv.createEnv)(options, (0, import_vite.loadEnv)(mode, process.cwd(), ""));
|
|
32
32
|
}
|
|
33
33
|
});
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import {
|
|
2
|
+
import { createEnv } from "arkenv";
|
|
3
3
|
import { loadEnv } from "vite";
|
|
4
4
|
var index_default = (options) => ({
|
|
5
5
|
name: "@arkenv/vite-plugin",
|
|
6
6
|
config(_config, { mode }) {
|
|
7
|
-
|
|
7
|
+
createEnv(options, loadEnv(mode, process.cwd(), ""));
|
|
8
8
|
}
|
|
9
9
|
});
|
|
10
10
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkenv/vite-plugin",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"author": "Yam Borodetsky <yam@yam.codes>",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -9,15 +9,18 @@
|
|
|
9
9
|
"main": "./dist/index.cjs",
|
|
10
10
|
"module": "./dist/index.js",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"arkenv": "0.
|
|
12
|
+
"arkenv": "0.3.0"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
|
+
"@vitejs/plugin-react": "^5.0.2",
|
|
15
16
|
"tsup": "^8.5.0",
|
|
16
|
-
"typescript": "^5.9.2"
|
|
17
|
+
"typescript": "^5.9.2",
|
|
18
|
+
"vite": "^7.0.0",
|
|
19
|
+
"vitest": "^3.2.4"
|
|
17
20
|
},
|
|
18
21
|
"peerDependencies": {
|
|
19
22
|
"arktype": "^2.0.0",
|
|
20
|
-
"vite": "^6.0.0"
|
|
23
|
+
"vite": "^6.0.0 || ^7.0.0"
|
|
21
24
|
},
|
|
22
25
|
"exports": {
|
|
23
26
|
"types": "./dist/index.d.ts",
|
|
@@ -29,7 +32,7 @@
|
|
|
29
32
|
"files": [
|
|
30
33
|
"dist"
|
|
31
34
|
],
|
|
32
|
-
"homepage": "https://
|
|
35
|
+
"homepage": "https://arkenv.js.org",
|
|
33
36
|
"keywords": [
|
|
34
37
|
"arktype",
|
|
35
38
|
"arkenv",
|