Socket
Book a DemoInstallSign in
Socket

vite-define-envs-plugin

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-define-envs-plugin

Embed environment variables as global constants for local js files.

0.5.0
latest
Source
npmnpm
Version published
Weekly downloads
101
-75.54%
Maintainers
1
Weekly downloads
 
Created
Source

vite-define-envs-plugin

Embed environment variables as global constants for local js files.

how it works

vite-define-envs-plugin will read from Node's process.env and define specific environment variables as global constants for client JavaScript.

read more about process.env

installation

npm install --save-dev vite-define-envs-plugin

arguments

  • keys - array of keys to read from process.env.
  • scope - scope of the global constants. Default to "process.env" if not set.

how to use

// vite.config.js

import viteDefineEnvs from "vite-define-envs-plugin";

export default {
    plugins: [
        new viteDefineEnvs(["USER", "API_BASE_URL"], "GLOBAL")
    ]
};


// your .js file

const appEnv = GLOBAL.USER;
const apiUrl = GLOBAL.API_BASE_URL;

avoid using process.env scope

It's not recommended to use process.env scope since it's not the same process.env that Node uses.

Local js files don't know about process.env, so the environment variables have to be processed and embedded by vite during the build time. On the other hand, in a Node application, process.env is a Node module and is injected at runtime.

Keywords

vite

FAQs

Package last updated on 27 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.