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