# gen-vite-env-types

> Takes your `.env` file as input

Latest version **1.0.0** (published 2021-10-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install gen-vite-env-types
pnpm add gen-vite-env-types
yarn add gen-vite-env-types
bun add gen-vite-env-types
```

Provides the command `gen-vite-env-types`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2021-10-22 |
| First published | 2021-10-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 7.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Gabriel Moraes |
| Maintainers | gabrielnafuzi |

## Links

- npm: https://www.npmjs.com/package/gen-vite-env-types
- npm.io page: https://npm.io/package/gen-vite-env-types

## Dependencies (2)

- [chalk](https://npm.io/package/chalk.md) ^4.0.0
- [dotenv](https://npm.io/package/dotenv.md) ^8.2.0

## Recent versions

- 1.0.0 (latest) — 2021-10-22

## README

# gen-vite-env-types

Takes your `.env` file as input

```sh
SESSION_SECRET=asdjpfowqip
STRIPE_ACCESS_TOKEN=qoi120wqe
```

And generates a `.d.ts` file

```typescript
interface ImportMetaEnv extends Readonly<Record<string, string>> {
  readonly VITE_SESSION_SECRET: string
  readonly VITE_STRIPE_ACCESS_TOKEN: string
}

interface ImportMeta {
  readonly env: ImportMetaEnv
}
```

Now `process.env.SESSION_SECRET` will autocomplete and be type-safe.

## Customize

`gen-vite-env-types` respects changes made to generated files, meaning you can overwrite `.env.example` and `env.d.ts` values, this can be helpful if you want a union type:

````typescript
interface ImportMetaEnv extends Readonly<Record<string, string>> {
  readonly NODE_ENV: 'development' | 'production'
}

interface ImportMeta {
  readonly env: ImportMetaEnv
}
```

Or if you want to persist `.env.example` values:

```sh
PORT=3000
````

## Usage

```bash
npx gen-vite-env-types path/to/.env
```

## Options

```
  -V, --version               Show version number
  -h, --help                  Show usage information
  -o, --types-output          Output name/path for types file | defaults to `env.d.ts`
  -e, --example-env-path      Path to save .env.example file
  -r, --rename-example-env    Custom name for .env example output file | defaults to `env.example` if omitted
```

## Examples with options

```bash
npx gen-vite-env-types .env -o src/types/env.d.ts -e .
```

```bash
# With custom example env file name
npx gen-vite-env-types .env -o src/types/env.d.ts -e . -r .env.test
```

---
_Source: https://npm.io/package/gen-vite-env-types · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
