Skip to content

The @ic-reactor/vite-plugin automates the generation of TypeScript declarations and Reactor hooks from your Candid files. It integrates seamlessly with Vite’s development server, providing hot-module replacement (HMR) for your canister interfaces.

bash pnpm add -D @ic-reactor/vite-plugin

Add the plugin to your vite.config.ts:

import { defineConfig } from "vite"
import react from "@vitejs/plugin-react"
import { icReactorPlugin } from "@ic-reactor/vite-plugin"
export default defineConfig({
plugins: [
react(),
icReactorPlugin({
canisters: [
{
name: "backend",
didFile: "src/backend/backend.did", // Path to your .did file
},
],
}),
],
})

The plugin automatically configures a proxy for /api requests to your local replica (defaulting to http://127.0.0.1:4943). This ensures your frontend can communicate with backend canisters during development without CORS issues.

The plugin automatically detects your network environment and canister IDs using the icp or dfx CLI. It injects this information into the ic_env cookie. This allows ClientManager to automatically resolve the correct canister IDs and network root key without manual configuration.

The plugin watches your .did files. When you modify a Candid file, it automatically:

  1. Regenerates the TypeScript declarations (.d.ts, .js factory).
  2. Regenerates the index.ts file with fully typed hooks.
  3. Restarts the Vite server to pick up the changes.
OptionTypeDescriptionDefault
canistersCanisterConfig[]List of canisters to generate hooks for (required).-
outDirstringBase output directory for generated files."src/declarations"
injectEnvironmentbooleanWhether to inject canister IDs into ic_env cookie.true
clientManagerPathstringPath to a custom ClientManager instance."../../clients"
OptionTypeDescriptionRequired
namestringName of the canister (used in generated code).Yes
didFilestringPath to the .did file.Yes
outDirstringOverride output directory for this canister.No
clientManagerPathstringOverride client manager path for this canister.No
canisterIdstringOptional fixed canister ID.No

Check out these examples to see the Vite plugin in action: