1.0.1 • Published 2 years ago

vite-plugin-watch-env v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

vite-plugin-watch-env

Apply .env file to process.env and watch file changes in vite.

Install

npm install vite-plugin-watch-env --save-dev
yarn add vite-plugin-watch-env -D
pnpm add vite-plugin-watch-env -D

Usage

// vite.config.ts
import { loadEnv, watchEnv } from 'vite-plugin-watch-env'

export default ({ mode }) => {
  loadEnv(`./.env.${mode}`)
  // here you can access env values from .env file
  console.log(process.env.TEST_ENV_VALUE)

  return defineConfig({
    plugins: [
      watchEnv(),
    ],
    define: {
      'process.env': {
        TEST_ENV_VALUE: process.env.TEST_ENV_VALUE,
      }
    }
  })
}