Basic Usage
Backend Configuration
Frontend Access
Variables are available aswindow.__ENV__:
How It Works
The middleware injects a script tag into your HTML:</head>, making variables available before your app loads.
Use Cases
API URLs
Analytics
Feature Flags
Multi-Environment Setup
Security Considerations
Never Inject Secrets
Only Inject Public Configuration
Prefixing Convention
Follow the convention of prefixing public variables:Build-Time vs Runtime
Build-Time (Vite/Webpack)
- Type-safe (TypeScript)
- Tree-shaking works
- Optimizations apply
- Must rebuild for each environment
- Canβt change without rebuild
Runtime (Mizu Injection)
- Single build for all environments
- Change without rebuild
- Dynamic configuration
- Not type-safe by default
- Available after page load
- Requires fallbacks
Hybrid Approach
Best of both worlds:TypeScript Support
Create type definitions:Testing
Mock in Tests
Environment-Specific Tests
Alternative: Meta Tags
You can also inject config via meta tags:- SEO-relevant config
- Prefer meta tags over script tags
- Framework requires meta tags