Vite runtime env plugin for investtal packages
npm install @investtal/vite-runtime-envThe default Vite config mechanism doesn't separate code and env following 12-Factors
This plugin solves the problem above by separating the env config into a separate module from the code bundle, opening the door for mounting and updating runtime config when running in a container environment.
Declare env following Vite convention:
.vite.config.ts
``javascript
import RuntimeEnv from '@investtal/vite-runtime-env';
import ViteReactRefresh from '@vitejs/plugin-react';
import { UserConfig } from 'vite';
const config: UserConfig = {
plugins: [...plugins, RuntimeEnv()],
};
`
client code:
`javascript``
console.log(window.__RUNTIME_ENV__);
console.log(window.__APP_METADATA__);