# @techmely/vite-plugin-runtime-env

> ## Problem

Latest version **1.1.1** (published 2022-08-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install @techmely/vite-plugin-runtime-env
pnpm add @techmely/vite-plugin-runtime-env
yarn add @techmely/vite-plugin-runtime-env
bun add @techmely/vite-plugin-runtime-env
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2022-08-07 |
| First published | 2021-12-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 16.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Harry Tran |
| Maintainers | thaycacac, nhattq.coding, hieuhani |

## Links

- npm: https://www.npmjs.com/package/@techmely/vite-plugin-runtime-env
- Repository: https://github.com/techmely/utils.git#dev
- Homepage: https://github.com/techmely/utils/tree/dev#readme
- Issues: https://github.com/techmely/utils/issues
- npm.io page: https://npm.io/package/@techmely/vite-plugin-runtime-env

## Dependencies (2)

- [dotenv](https://npm.io/package/dotenv.md) 16.0.1
- [@techmely/utils](https://npm.io/package/@techmely/utils.md) 1.4.3

## Recent versions

- 1.1.1 (latest) — 2022-08-07
- 1.0.10 — 2022-04-27
- 1.0.9 — 2022-04-16
- 1.1.0 — 2022-03-21
- 1.0.8 — 2022-01-10
- 1.0.7 — 2022-01-10
- 1.0.6 — 2022-01-09
- 1.0.5 — 2021-12-28
- 1.0.4 — 2021-12-26
- 1.0.3 — 2021-12-26
- 1.0.2 — 2021-12-26
- 1.0.1 — 2021-12-26
- 1.0.0 — 2021-12-19

## README

# Vite-plugin-runtime-env

## Problem

Cơ chế sẵn có của Vite không cho phép phân tách code và env theo chuẩn [12-Factors](https://12factor.net/)

## Solution

Plugin này giải quyết vấn đề trên bằng cách tách config env ra 1 module riêng khỏi code bundle, mở ra cánh cửa cho việc mount và update config runtime khi chạy trên môi trường container.

## Usage

Khai báo env như convention của Vite: <https://vitejs.dev/guide/env-and-mode.html> .env.production

```javascript
ENV=production
USER_API_URL=https://services.user.com
```

.vite.config.ts

```javascript
import ViteRuntimeEnv from '@techmely/vite-plugin-runtime-env';
import { UserConfig } from 'vite';

const config: UserConfig = {
  plugins: [ViteRuntimeEnv()]
};
```

client code:

```javascript
console.log(window._env_.ENV); // "production"
```

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