🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

@geprog/vite-plugin-env-config

Package Overview
Dependencies
Maintainers
3
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@geprog/vite-plugin-env-config

Vite Plugin for providing config from environment variables at runtime

4.0.14
latest
Source
npm
Version published
Maintainers
3
Created
Source

@geprog/vite-plugin-env-config

npm version vite peer dependency version

Vite plugin for providing configurations from environment variables at runtime.

The generated template can be populated with envsubst in production.

Usage

Add envConfig plugin to vite.config.js / vite.config.ts and provide a list of environment variable names:

// vite.config.js / vite.config.ts
import { envConfig } from '@geprog/vite-plugin-env-config';

export default {
  plugins: [envConfig({ variables: ['BACKEND_URL'] })],
};

To access the environment variables use the built-in getter:

import { getEnvConfig } from '@geprog/vite-plugin-env-config';

const backendURL = getEnvConfig('BACKEND_URL');

For production use envsubst as outlined in the next section.

Motivation

To adhere to the principles of the twelve-factor app you might need to access environment variables that are set when your frontend server starts. Instead of building your frontend on startup, you can use a config template like the one above and populate it using envsubst:

CMD ["/bin/sh", "-c", "envsubst < ./dist/env-config.template.js > ./dist/env-config.js && exec nginx -g 'daemon off;'"]

@geprog/vite-plugin-env-config generates the required template from a list of variable names and provides the already populated file via the dev-server during development.

FAQs

Package last updated on 19 Mar 2024

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