vite-plugin-env-config
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

vite-plugin-env-config

Set vite config options with environment variables

Installation

pnpm i -D vite-plugin-env-config

Usage

add to vite config

// vite config
import { defineConfig } from 'vite';
import { envConfig } from 'vite-plugin-env-config';

export default defineConfig({
	plugins: [
		envConfig({
			/* plugin options */
		})
	]
});

use environment variables to specify config values on the fly

# this calls vite build with build.minify set to false in resolved config
VITECONFIG_build_minify=false vite build

Options

interface Options {
	/**
	 * prefix of env variables to look for
	 * @default VITECONFIG_
	 */
	prefix: string;

	/**
	 * seprarator for path splits, should be one or multiple _
	 *
	 * eg VITECONFIG_foo_bar=3 gets converted to {foo:{bar: 3}}
	 * @default _
	 */
	separator: string;
}

Environment variables have a limited charset

  • Use A-Z_ chars for prefix
  • separator should be left at _ for regular use, if you want to set a property that contains a _, use __

Limitations

  • uses JSON.parse to parse values, what cannot be parsed will be converted to string
  • can only set object properties, not array items

License

MIT

Package Sidebar

Install

npm i vite-plugin-env-config

Weekly Downloads

75

Version

2.0.1

License

MIT

Unpacked Size

16.1 kB

Total Files

13

Last publish

Collaborators

  • dominik_g