@ic-reactor/vite-plugin 0.4.1 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -114
- package/dist/index.cjs +67 -88
- package/dist/index.d.cts +19 -38
- package/dist/index.d.ts +19 -38
- package/dist/index.js +67 -90
- package/package.json +3 -4
- package/src/env.ts +80 -0
- package/src/index.test.ts +21 -99
- package/src/index.ts +94 -184
package/README.md
CHANGED
|
@@ -11,15 +11,14 @@
|
|
|
11
11
|
|
|
12
12
|
---
|
|
13
13
|
|
|
14
|
-
Automatically generate type-safe React hooks for your Internet Computer canisters. This plugin watches your `.did` files and generates ready-to-use hooks with full TypeScript support.
|
|
14
|
+
Automatically generate type-safe React hooks for your Internet Computer canisters. This plugin watches your `.did` files and generates ready-to-use hooks with full TypeScript support using the shared `@ic-reactor/codegen` pipeline.
|
|
15
15
|
|
|
16
16
|
## Features
|
|
17
17
|
|
|
18
18
|
- ⚡ **Zero Config** — Point to your `.did` file and get hooks instantly
|
|
19
|
-
- 🔄 **Hot Reload** — Automatically regenerates hooks when `.did` files change
|
|
20
|
-
- 📦 **TypeScript Declarations** — Full type safety
|
|
21
|
-
-
|
|
22
|
-
- 🔌 **Flexible** — Works with any `ClientManager` configuration
|
|
19
|
+
- 🔄 **Hot Reload** — Automatically regenerates hooks and types when `.did` files change
|
|
20
|
+
- 📦 **TypeScript Declarations** — Full built-in type safety
|
|
21
|
+
- 🌍 **Auto Environment** — Automatically detects local replica and injects `ic_env` cookie
|
|
23
22
|
|
|
24
23
|
## Installation
|
|
25
24
|
|
|
@@ -58,26 +57,29 @@ export default defineConfig({
|
|
|
58
57
|
|
|
59
58
|
### 2. Create Your ClientManager
|
|
60
59
|
|
|
61
|
-
The plugin
|
|
60
|
+
The plugin looks for a client manager to import. By default, it expects it at `../../clients` relative to the generated files.
|
|
62
61
|
|
|
63
62
|
```typescript
|
|
64
|
-
// src/
|
|
63
|
+
// src/clients.ts
|
|
65
64
|
import { ClientManager } from "@ic-reactor/react"
|
|
66
65
|
import { QueryClient } from "@tanstack/react-query"
|
|
67
66
|
|
|
68
67
|
export const queryClient = new QueryClient()
|
|
69
|
-
export const clientManager = new ClientManager({
|
|
68
|
+
export const clientManager = new ClientManager({
|
|
69
|
+
queryClient,
|
|
70
|
+
withCanisterEnv: true, // Important for cookie injection support
|
|
71
|
+
})
|
|
70
72
|
```
|
|
71
73
|
|
|
72
74
|
### 3. Use Generated Hooks
|
|
73
75
|
|
|
74
|
-
The plugin generates
|
|
76
|
+
The plugin generates headers in `src/declarations/<name>/index.ts` by default.
|
|
75
77
|
|
|
76
78
|
```tsx
|
|
77
|
-
import {
|
|
79
|
+
import { useBackendQuery } from "./declarations/backend"
|
|
78
80
|
|
|
79
81
|
function MyComponent() {
|
|
80
|
-
const { data, isPending } =
|
|
82
|
+
const { data, isPending } = useBackendQuery({
|
|
81
83
|
functionName: "get_message",
|
|
82
84
|
})
|
|
83
85
|
|
|
@@ -89,116 +91,32 @@ function MyComponent() {
|
|
|
89
91
|
|
|
90
92
|
### Plugin Options
|
|
91
93
|
|
|
92
|
-
| Option | Type | Description
|
|
93
|
-
| :------------------ | :----------------- |
|
|
94
|
-
| `canisters` | `CanisterConfig[]` | List of canisters to generate hooks for.
|
|
95
|
-
| `outDir` | `string` | Base output directory for generated files.
|
|
96
|
-
| `
|
|
97
|
-
| `
|
|
94
|
+
| Option | Type | Description | Default |
|
|
95
|
+
| :------------------ | :----------------- | :-------------------------------------------------- | :------------------- |
|
|
96
|
+
| `canisters` | `CanisterConfig[]` | List of canisters to generate hooks for (required). | - |
|
|
97
|
+
| `outDir` | `string` | Base output directory for generated files. | `"src/declarations"` |
|
|
98
|
+
| `clientManagerPath` | `string` | Path to client manager import. | `"../../clients"` |
|
|
99
|
+
| `injectEnvironment` | `boolean` | Inject `ic_env` cookie for local development. | `true` |
|
|
98
100
|
|
|
99
101
|
### Canister Config
|
|
100
102
|
|
|
101
|
-
| Option | Type
|
|
102
|
-
| :------------------ |
|
|
103
|
-
| `name` | `string`
|
|
104
|
-
| `didFile` | `string`
|
|
105
|
-
| `outDir` | `string`
|
|
106
|
-
| `
|
|
107
|
-
| `
|
|
108
|
-
|
|
109
|
-
## How It Works
|
|
110
|
-
|
|
111
|
-
1. **Build Start**: The plugin reads your `.did` files and generates TypeScript declarations (`.js` and `.d.ts`).
|
|
112
|
-
2. **Code Generation**: Creates a reactor instance and typed hooks (using `createActorHooks`) for each canister in `index.ts`.
|
|
113
|
-
3. **Hot Reload**: Watches for `.did` file changes and regenerates everything automatically.
|
|
114
|
-
4. **Local Proxy**: Configures a Vite proxy to redirect `/api` calls to your local replica.
|
|
115
|
-
5. **Environment Detection**: Automatically injects canister IDs from `icp-cli` or `dfx` cache into your session.
|
|
116
|
-
|
|
117
|
-
## DisplayReactor vs Reactor
|
|
118
|
-
|
|
119
|
-
By default, the plugin uses `DisplayReactor` which transforms Candid types into React-friendly formats:
|
|
120
|
-
|
|
121
|
-
| Candid Type | Reactor | DisplayReactor |
|
|
122
|
-
| ----------- | ------------ | -------------- |
|
|
123
|
-
| `nat` | `bigint` | `string` |
|
|
124
|
-
| `int` | `bigint` | `string` |
|
|
125
|
-
| `principal` | `Principal` | `string` |
|
|
126
|
-
| `vec nat8` | `Uint8Array` | `string` (hex) |
|
|
127
|
-
|
|
128
|
-
To use raw Candid types:
|
|
129
|
-
|
|
130
|
-
```typescript
|
|
131
|
-
icReactorPlugin({
|
|
132
|
-
canisters: [
|
|
133
|
-
{
|
|
134
|
-
name: "backend",
|
|
135
|
-
didFile: "./backend/backend.did",
|
|
136
|
-
useDisplayReactor: false, // Use Reactor instead
|
|
137
|
-
},
|
|
138
|
-
],
|
|
139
|
-
})
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
## Integration with ICP CLI
|
|
143
|
-
|
|
144
|
-
`@ic-reactor/vite-plugin` now supports **zero-config local `icp-cli` canister env injection** during `vite dev`.
|
|
145
|
-
|
|
146
|
-
When dev server starts, the plugin automatically tries to read:
|
|
147
|
-
|
|
148
|
-
- `.icp/cache/mappings/local.ids.json`
|
|
149
|
-
|
|
150
|
-
If present, it sets an `ic_env` cookie with:
|
|
151
|
-
|
|
152
|
-
- `ic_root_key=<local-root-key>`
|
|
153
|
-
- `PUBLIC_CANISTER_ID:<name>=<canister-id>`
|
|
154
|
-
|
|
155
|
-
This means `withCanisterEnv: true` works out of the box after `icp deploy`, without custom cookie code in `vite.config.ts`.
|
|
156
|
-
|
|
157
|
-
```typescript
|
|
158
|
-
// vite.config.ts
|
|
159
|
-
import { defineConfig } from "vite"
|
|
160
|
-
import react from "@vitejs/plugin-react"
|
|
161
|
-
import { icReactorPlugin } from "@ic-reactor/vite-plugin"
|
|
162
|
-
|
|
163
|
-
export default defineConfig({
|
|
164
|
-
plugins: [
|
|
165
|
-
react(),
|
|
166
|
-
icReactorPlugin({
|
|
167
|
-
canisters: [
|
|
168
|
-
{
|
|
169
|
-
name: "backend",
|
|
170
|
-
didFile: "./backend/backend.did",
|
|
171
|
-
},
|
|
172
|
-
],
|
|
173
|
-
}),
|
|
174
|
-
],
|
|
175
|
-
})
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
If you need to disable this behavior:
|
|
179
|
-
|
|
180
|
-
```typescript
|
|
181
|
-
icReactorPlugin({
|
|
182
|
-
canisters: [...],
|
|
183
|
-
injectEnvironment: false,
|
|
184
|
-
})
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
## Requirements
|
|
188
|
-
|
|
189
|
-
- **Vite 5.x, 6.x, or 7.x**
|
|
190
|
-
- **Node.js 18+**
|
|
191
|
-
- **TypeScript 5.0+**
|
|
103
|
+
| Option | Type | Description | Required |
|
|
104
|
+
| :------------------ | :------- | :---------------------------------------------- | :------- |
|
|
105
|
+
| `name` | `string` | Name of the canister (used for variable names). | Yes |
|
|
106
|
+
| `didFile` | `string` | Path to the `.did` file. | Yes |
|
|
107
|
+
| `outDir` | `string` | Override output directory for this canister. | No |
|
|
108
|
+
| `clientManagerPath` | `string` | Override client manager path. | No |
|
|
109
|
+
| `canisterId` | `string` | Optional fixed canister ID. | No |
|
|
192
110
|
|
|
193
|
-
##
|
|
111
|
+
## Local Development (Environment Injection)
|
|
194
112
|
|
|
195
|
-
|
|
196
|
-
- [@ic-reactor/core](https://www.npmjs.com/package/@ic-reactor/core) — Core reactor functionality
|
|
197
|
-
- [@icp-sdk/bindgen](https://www.npmjs.com/package/@icp-sdk/bindgen) — Candid binding generator
|
|
113
|
+
When running `vite dev`, the plugin automatically handles local canister environment connection:
|
|
198
114
|
|
|
199
|
-
|
|
115
|
+
1. Detects your local environment (using `icp` or `dfx` CLI).
|
|
116
|
+
2. Sets an `ic_env` cookie containing the root key and canister IDs.
|
|
117
|
+
3. Sets up a proxy for `/api` to your local replica.
|
|
200
118
|
|
|
201
|
-
|
|
119
|
+
This means you **don't** need complex `vite.config.ts` proxy rules or manual `.env` file management for local addresses — it just works.
|
|
202
120
|
|
|
203
121
|
## License
|
|
204
122
|
|
package/dist/index.cjs
CHANGED
|
@@ -33,16 +33,19 @@ __export(index_exports, {
|
|
|
33
33
|
icReactorPlugin: () => icReactorPlugin
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(index_exports);
|
|
36
|
-
var
|
|
37
|
-
var import_path = __toESM(require("path"), 1);
|
|
38
|
-
var import_child_process = require("child_process");
|
|
36
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
39
37
|
var import_codegen = require("@ic-reactor/codegen");
|
|
38
|
+
|
|
39
|
+
// src/env.ts
|
|
40
|
+
var import_child_process = require("child_process");
|
|
40
41
|
function getIcEnvironmentInfo(canisterNames) {
|
|
41
42
|
const environment = process.env.ICP_ENVIRONMENT || "local";
|
|
42
43
|
try {
|
|
43
44
|
const networkStatus = JSON.parse(
|
|
44
45
|
(0, import_child_process.execFileSync)("icp", ["network", "status", "-e", environment, "--json"], {
|
|
45
|
-
encoding: "utf-8"
|
|
46
|
+
encoding: "utf-8",
|
|
47
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
48
|
+
// suppress stderr
|
|
46
49
|
})
|
|
47
50
|
);
|
|
48
51
|
const rootKey = networkStatus.root_key;
|
|
@@ -53,35 +56,48 @@ function getIcEnvironmentInfo(canisterNames) {
|
|
|
53
56
|
const canisterId = (0, import_child_process.execFileSync)(
|
|
54
57
|
"icp",
|
|
55
58
|
["canister", "status", name, "-e", environment, "-i"],
|
|
56
|
-
{
|
|
57
|
-
encoding: "utf-8"
|
|
58
|
-
}
|
|
59
|
+
{ encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }
|
|
59
60
|
).trim();
|
|
60
|
-
|
|
61
|
+
if (canisterId) {
|
|
62
|
+
canisterIds[name] = canisterId;
|
|
63
|
+
}
|
|
61
64
|
} catch {
|
|
62
65
|
}
|
|
63
66
|
}
|
|
64
67
|
return { environment, rootKey, proxyTarget, canisterIds };
|
|
65
|
-
} catch {
|
|
68
|
+
} catch (error) {
|
|
66
69
|
return null;
|
|
67
70
|
}
|
|
68
71
|
}
|
|
69
72
|
function buildIcEnvCookie(canisterIds, rootKey) {
|
|
70
|
-
const
|
|
73
|
+
const parts = [`ic_root_key=${rootKey}`];
|
|
71
74
|
for (const [name, id] of Object.entries(canisterIds)) {
|
|
72
|
-
|
|
75
|
+
parts.push(`PUBLIC_CANISTER_ID:${name}=${id}`);
|
|
73
76
|
}
|
|
74
|
-
return encodeURIComponent(
|
|
77
|
+
return encodeURIComponent(parts.join("&"));
|
|
75
78
|
}
|
|
79
|
+
|
|
80
|
+
// src/index.ts
|
|
76
81
|
function icReactorPlugin(options) {
|
|
77
|
-
const
|
|
78
|
-
|
|
82
|
+
const {
|
|
83
|
+
canisters,
|
|
84
|
+
outDir = "src/declarations",
|
|
85
|
+
clientManagerPath = "../../clients",
|
|
86
|
+
injectEnvironment = true
|
|
87
|
+
} = options;
|
|
88
|
+
const globalConfig = {
|
|
89
|
+
outDir,
|
|
90
|
+
clientManagerPath
|
|
91
|
+
};
|
|
92
|
+
const plugin = {
|
|
79
93
|
name: "ic-reactor-plugin",
|
|
80
|
-
|
|
81
|
-
|
|
94
|
+
enforce: "pre",
|
|
95
|
+
// Run before other plugins
|
|
96
|
+
config(config, { command }) {
|
|
97
|
+
if (command !== "serve" || !injectEnvironment) {
|
|
82
98
|
return {};
|
|
83
99
|
}
|
|
84
|
-
const canisterNames =
|
|
100
|
+
const canisterNames = canisters.map((c) => c.name).filter((n) => !!n);
|
|
85
101
|
if (!canisterNames.includes("internet_identity")) {
|
|
86
102
|
canisterNames.push("internet_identity");
|
|
87
103
|
}
|
|
@@ -114,95 +130,58 @@ function icReactorPlugin(options) {
|
|
|
114
130
|
};
|
|
115
131
|
},
|
|
116
132
|
async buildStart() {
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
133
|
+
const projectRoot = process.cwd();
|
|
134
|
+
console.log(
|
|
135
|
+
`[ic-reactor] Generating hooks for ${canisters.length} canisters...`
|
|
120
136
|
);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
for (const canister of options.canisters) {
|
|
130
|
-
let didFile = canister.didFile;
|
|
131
|
-
const outDir = canister.outDir ?? import_path.default.join(baseOutDir, canister.name);
|
|
132
|
-
if (!didFile) {
|
|
133
|
-
const environment = process.env.ICP_ENVIRONMENT || "local";
|
|
134
|
-
console.log(
|
|
135
|
-
`[ic-reactor] didFile not specified for "${canister.name}". Attempting to download from canister...`
|
|
136
|
-
);
|
|
137
|
-
try {
|
|
138
|
-
const candidContent = (0, import_child_process.execFileSync)(
|
|
139
|
-
"icp",
|
|
140
|
-
[
|
|
141
|
-
"canister",
|
|
142
|
-
"metadata",
|
|
143
|
-
canister.name,
|
|
144
|
-
"candid:service",
|
|
145
|
-
"-e",
|
|
146
|
-
environment
|
|
147
|
-
],
|
|
148
|
-
{ encoding: "utf-8" }
|
|
149
|
-
).trim();
|
|
150
|
-
const declarationsDir = import_path.default.join(outDir, "declarations");
|
|
151
|
-
if (!import_fs.default.existsSync(declarationsDir)) {
|
|
152
|
-
import_fs.default.mkdirSync(declarationsDir, { recursive: true });
|
|
153
|
-
}
|
|
154
|
-
didFile = import_path.default.join(declarationsDir, `${canister.name}.did`);
|
|
155
|
-
import_fs.default.writeFileSync(didFile, candidContent);
|
|
156
|
-
console.log(
|
|
157
|
-
`[ic-reactor] Candid downloaded and saved to ${didFile}`
|
|
158
|
-
);
|
|
159
|
-
} catch (error) {
|
|
137
|
+
for (const canisterConfig of canisters) {
|
|
138
|
+
try {
|
|
139
|
+
const result = await (0, import_codegen.runCanisterPipeline)({
|
|
140
|
+
canisterConfig,
|
|
141
|
+
projectRoot,
|
|
142
|
+
globalConfig
|
|
143
|
+
});
|
|
144
|
+
if (!result.success) {
|
|
160
145
|
console.error(
|
|
161
|
-
`[ic-reactor] Failed to
|
|
146
|
+
`[ic-reactor] Failed to generate ${canisterConfig.name}: ${result.error}`
|
|
162
147
|
);
|
|
163
|
-
|
|
148
|
+
} else {
|
|
164
149
|
}
|
|
165
|
-
}
|
|
166
|
-
console.log(
|
|
167
|
-
`[ic-reactor] Generating hooks for ${canister.name} from ${didFile}`
|
|
168
|
-
);
|
|
169
|
-
const result = await (0, import_codegen.generateDeclarations)({
|
|
170
|
-
didFile,
|
|
171
|
-
outDir,
|
|
172
|
-
canisterName: canister.name
|
|
173
|
-
});
|
|
174
|
-
if (!result.success) {
|
|
150
|
+
} catch (err) {
|
|
175
151
|
console.error(
|
|
176
|
-
`[ic-reactor]
|
|
152
|
+
`[ic-reactor] Error generating ${canisterConfig.name}:`,
|
|
153
|
+
err
|
|
177
154
|
);
|
|
178
|
-
continue;
|
|
179
155
|
}
|
|
180
|
-
const reactorContent = (0, import_codegen.generateReactorFile)({
|
|
181
|
-
canisterName: canister.name,
|
|
182
|
-
didFile,
|
|
183
|
-
clientManagerPath: canister.clientManagerPath ?? options.clientManagerPath
|
|
184
|
-
});
|
|
185
|
-
const reactorPath = import_path.default.join(outDir, "index.ts");
|
|
186
|
-
import_fs.default.mkdirSync(outDir, { recursive: true });
|
|
187
|
-
import_fs.default.writeFileSync(reactorPath, reactorContent);
|
|
188
|
-
console.log(`[ic-reactor] Reactor hooks generated at ${reactorPath}`);
|
|
189
156
|
}
|
|
190
157
|
},
|
|
191
158
|
handleHotUpdate({ file, server }) {
|
|
192
159
|
if (file.endsWith(".did")) {
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
return
|
|
160
|
+
const affectedCanister = canisters.find((c) => {
|
|
161
|
+
const configPath = import_node_path.default.resolve(process.cwd(), c.didFile);
|
|
162
|
+
return configPath === file;
|
|
196
163
|
});
|
|
197
|
-
if (
|
|
164
|
+
if (affectedCanister) {
|
|
198
165
|
console.log(
|
|
199
|
-
`[ic-reactor]
|
|
166
|
+
`[ic-reactor] .did file changed: ${affectedCanister.name}. Regenerating...`
|
|
200
167
|
);
|
|
201
|
-
|
|
168
|
+
const projectRoot = process.cwd();
|
|
169
|
+
(0, import_codegen.runCanisterPipeline)({
|
|
170
|
+
canisterConfig: affectedCanister,
|
|
171
|
+
projectRoot,
|
|
172
|
+
globalConfig
|
|
173
|
+
}).then((result) => {
|
|
174
|
+
if (result.success) {
|
|
175
|
+
server.ws.send({ type: "full-reload" });
|
|
176
|
+
} else {
|
|
177
|
+
console.error(`[ic-reactor] Regeneration failed: ${result.error}`);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
202
180
|
}
|
|
203
181
|
}
|
|
204
182
|
}
|
|
205
183
|
};
|
|
184
|
+
return plugin;
|
|
206
185
|
}
|
|
207
186
|
// Annotate the CommonJS export names for ESM import in node:
|
|
208
187
|
0 && (module.exports = {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,55 +1,36 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CanisterConfig } from '@ic-reactor/codegen';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* @ic-reactor/vite-plugin
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* import { icReactorPlugin } from "@ic-reactor/vite-plugin"
|
|
12
|
-
*
|
|
13
|
-
* export default defineConfig({
|
|
14
|
-
* plugins: [
|
|
15
|
-
* icReactorPlugin({
|
|
16
|
-
* canisters: [
|
|
17
|
-
* {
|
|
18
|
-
* name: "backend",
|
|
19
|
-
* didFile: "../backend/backend.did",
|
|
20
|
-
* clientManagerPath: "../lib/client"
|
|
21
|
-
* }
|
|
22
|
-
* ]
|
|
23
|
-
* })
|
|
24
|
-
* ]
|
|
25
|
-
* })
|
|
26
|
-
* ```
|
|
6
|
+
* Vite plugin that:
|
|
7
|
+
* 1. Generates hooks at build time (using @ic-reactor/codegen pipeline)
|
|
8
|
+
* 2. Injects `ic_env` cookie for local development (via proxy)
|
|
9
|
+
* 3. Hot-reloads when .did files change
|
|
27
10
|
*/
|
|
28
11
|
|
|
29
|
-
interface CanisterConfig {
|
|
30
|
-
name: string;
|
|
31
|
-
outDir?: string;
|
|
32
|
-
didFile?: string;
|
|
33
|
-
clientManagerPath?: string;
|
|
34
|
-
}
|
|
35
12
|
interface IcReactorPluginOptions {
|
|
36
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Canister configurations.
|
|
15
|
+
* `name` is required for each canister.
|
|
16
|
+
*/
|
|
37
17
|
canisters: CanisterConfig[];
|
|
38
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Default output directory (relative to project root).
|
|
20
|
+
* Default: "src/declarations"
|
|
21
|
+
*/
|
|
39
22
|
outDir?: string;
|
|
40
23
|
/**
|
|
41
|
-
*
|
|
24
|
+
* Default client manager import path.
|
|
42
25
|
* Default: "../../clients"
|
|
43
26
|
*/
|
|
44
27
|
clientManagerPath?: string;
|
|
45
28
|
/**
|
|
46
|
-
* Automatically inject
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* This is useful for local development with `icp`.
|
|
29
|
+
* Automatically inject `ic_env` cookie for local development?
|
|
30
|
+
* Default: true
|
|
50
31
|
*/
|
|
51
32
|
injectEnvironment?: boolean;
|
|
52
33
|
}
|
|
53
|
-
declare function icReactorPlugin(options: IcReactorPluginOptions):
|
|
34
|
+
declare function icReactorPlugin(options: IcReactorPluginOptions): any;
|
|
54
35
|
|
|
55
|
-
export { type
|
|
36
|
+
export { type IcReactorPluginOptions, icReactorPlugin };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,55 +1,36 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CanisterConfig } from '@ic-reactor/codegen';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* @ic-reactor/vite-plugin
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* import { icReactorPlugin } from "@ic-reactor/vite-plugin"
|
|
12
|
-
*
|
|
13
|
-
* export default defineConfig({
|
|
14
|
-
* plugins: [
|
|
15
|
-
* icReactorPlugin({
|
|
16
|
-
* canisters: [
|
|
17
|
-
* {
|
|
18
|
-
* name: "backend",
|
|
19
|
-
* didFile: "../backend/backend.did",
|
|
20
|
-
* clientManagerPath: "../lib/client"
|
|
21
|
-
* }
|
|
22
|
-
* ]
|
|
23
|
-
* })
|
|
24
|
-
* ]
|
|
25
|
-
* })
|
|
26
|
-
* ```
|
|
6
|
+
* Vite plugin that:
|
|
7
|
+
* 1. Generates hooks at build time (using @ic-reactor/codegen pipeline)
|
|
8
|
+
* 2. Injects `ic_env` cookie for local development (via proxy)
|
|
9
|
+
* 3. Hot-reloads when .did files change
|
|
27
10
|
*/
|
|
28
11
|
|
|
29
|
-
interface CanisterConfig {
|
|
30
|
-
name: string;
|
|
31
|
-
outDir?: string;
|
|
32
|
-
didFile?: string;
|
|
33
|
-
clientManagerPath?: string;
|
|
34
|
-
}
|
|
35
12
|
interface IcReactorPluginOptions {
|
|
36
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Canister configurations.
|
|
15
|
+
* `name` is required for each canister.
|
|
16
|
+
*/
|
|
37
17
|
canisters: CanisterConfig[];
|
|
38
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Default output directory (relative to project root).
|
|
20
|
+
* Default: "src/declarations"
|
|
21
|
+
*/
|
|
39
22
|
outDir?: string;
|
|
40
23
|
/**
|
|
41
|
-
*
|
|
24
|
+
* Default client manager import path.
|
|
42
25
|
* Default: "../../clients"
|
|
43
26
|
*/
|
|
44
27
|
clientManagerPath?: string;
|
|
45
28
|
/**
|
|
46
|
-
* Automatically inject
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* This is useful for local development with `icp`.
|
|
29
|
+
* Automatically inject `ic_env` cookie for local development?
|
|
30
|
+
* Default: true
|
|
50
31
|
*/
|
|
51
32
|
injectEnvironment?: boolean;
|
|
52
33
|
}
|
|
53
|
-
declare function icReactorPlugin(options: IcReactorPluginOptions):
|
|
34
|
+
declare function icReactorPlugin(options: IcReactorPluginOptions): any;
|
|
54
35
|
|
|
55
|
-
export { type
|
|
36
|
+
export { type IcReactorPluginOptions, icReactorPlugin };
|