Frontend with Vite
Frontend with Vite
If your app already uses VITE_*, keep that shape first and let CNOS generate it.
cnos build public --framework vite --profile local --to .env.localcnos dev env --public --framework vite --profile local --to .env.local -- pnpm devPromote browser-safe values:
public: promote: - value.app.apiBaseUrlUse the Vite plugin:
import { defineConfig } from 'vite';import { createCnosVitePlugin } from '@kitsy/cnos-vite';
export default defineConfig({ plugins: [createCnosVitePlugin()],});Read in client code:
import cnos from '@kitsy/cnos/browser';
console.log(cnos('public.app.apiBaseUrl'));console.log(import.meta.env.VITE_APP_API_BASE_URL);Migration path:
- keep
VITE_*working through generated env files - add
createCnosVitePlugin() - move browser reads to
@kitsy/cnos/browser - stop treating handwritten
.env.localas the source of truth