Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

vite-plugin-env-config

svitejs232MIT2.0.1TypeScript support: included

Set vite config options with environment variables

vite-plugin, vite plugin, vite, config

readme

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

changelog

vite-plugin-env-config

2.0.1

Patch Changes

  • dummy release to test release job permissions (#42)

2.0.0

Major Changes

  • drop support for node12 (#34)

1.0.1

Patch Changes

  • dummy release to test switch of changelog generator (#14)