Skip to content

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

Notifications You must be signed in to change notification settings

Enoooch/vite-plugin-watch-env

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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,
      }
    }
  })
}

About

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

Topics

Resources

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published