Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vite-plugin-env-file

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-env-file

This Vite plugin allows you to dynamically update your `.env` file during the build process. It's particularly useful for injecting environment variables that depend on the build or development server settings.

  • 1.0.0
  • npm
  • Socket score

Version published
Weekly downloads
54
decreased by-21.74%
Maintainers
1
Weekly downloads
 
Created
Source

Vite Plugin Env File

This Vite plugin allows you to dynamically update your .env file during the build process. It's particularly useful for injecting environment variables that depend on the build or development server settings.

Installation

To install the plugin, you can use either npm or yarn. Run one of the following commands in your project directory:

npm install vite-plugin-env-file or yarn add vite-plugin-env-file

Usage

Add it to vite.config.js

import viteEnvFile from  'vite-plugin-env-file'

export default {
  plugins: [
     viteEnvFile({
        dev_server_port: 3008,
        dev_server_public_url: 'https://www.vite.com',
        dev_server_enabled: true
      })
  ],
}

This would render a vite.env in the project root with something like this:

VITE_DEV_SERVER_PORT="3008"
VITE_DEV_SERVER_PUBLIC_URL="https://www.vite.com"
VITE_DEV_SERVER_ENABLED="true"

When the buildEnd method is called, these variables and vite.env file are deleted.

Options

The plugin function takes two arguments: envVars and options.

envVars

  • Type: object or falsy
  • Description: An object containing the environment variables to be set. If falsy, the plugin does nothing.
  • Example: { 'custom_var': 'value' }

options

  • Type: object (optional)
  • Description: Configuration options for the plugin.
  • Properties:
    • prefix: The prefix to be added to all environment variable names.
      • Type: string
      • Default: 'VITE_'
    • forceUpperCase: Whether to convert all environment variable names to uppercase.
      • Type: boolean
      • Default: true
    • envFile: The name of the environment file to be updated.
      • Type: string
      • Default: 'vite.env'

Keywords

FAQs

Package last updated on 20 Nov 2023

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc