Vite plugin that provides Internet Computer Canister Dapp environment configuration
Features:
Works in all build modes (development and production)
Accepts optional environment configurations for both dev and prod in vite.config.ts
Provides sensible defaults for both environments if not specified
Embeds both configurations into the build for runtime environment detection
Automatic server proxy setup for IC development (only in Vite dev server)
/api -> proxied to configured host
/canister-dashboard -> proxied to ${host}/canister-dashboard?canisterId=${viteDevCanisterId}
/.well-known/ii-alternative-origins -> proxied to ${host}/.well-known/ii-alternative-origins?canisterId=${viteDevCanisterId}
Note: The last two proxy rules are only set if viteDevCanisterId is provided
Note: Existing user-defined proxy rules for these paths will not be overwritten
This plugin enables building a single WASM that works in all environments by:
Embedding both dev and prod configurations in the build
Detecting environment at runtime based on URL origin (http://, localhost, 127.0.0.1 = dev)
Automatically switching between configurations based on where the app is accessed
Providing canister ID inference with automatic URL-based detection and Vite dev server fallback
This plugin is designed to:
Enable runtime environment inference for any canister dapp frontend
Signal the environment to the canister dashboard (which shares the same environment)
Support development of the dashboard frontend itself
Provide canister ID inference that works in all deployment scenarios
Vite plugin that provides Internet Computer Canister Dapp environment configuration
Features:
/api-> proxied to configured host/canister-dashboard-> proxied to${host}/canister-dashboard?canisterId=${viteDevCanisterId}/.well-known/ii-alternative-origins-> proxied to${host}/.well-known/ii-alternative-origins?canisterId=${viteDevCanisterId}Note: The last two proxy rules are only set if viteDevCanisterId is provided Note: Existing user-defined proxy rules for these paths will not be overwrittenThis plugin enables building a single WASM that works in all environments by:
This plugin is designed to:
Default configurations:
Example usage in vite.config.ts:
Frontend usage with helper functions: