Skip to content

Commit 1cb4de9

Browse files
ilberttnathanosdev
andauthored
docs: add library development guides (#1128)
* docs: add library development guides * docs: update installation guide --------- Co-authored-by: Nathan Mc Grath <contact@nathanos.dev>
1 parent 0d8a839 commit 1cb4de9

File tree

4 files changed

+85
-1
lines changed

4 files changed

+85
-1
lines changed

docs/astro.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export default defineConfig({
5252
{ label: 'Installation', link: '/installation' },
5353
{ label: 'Quick Start', link: '/quick-start' },
5454
{ label: 'Typescript', link: '/typescript' },
55+
{ label: 'Library Development', link: '/library-development' },
5556
],
5657
},
5758
],

docs/src/content/docs/installation.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ The `@icp-sdk/core` is a single, unified package that contains all the modules y
2222
</TabItem>
2323
</Tabs>
2424

25+
> If you're using pnpm, you might need to install the peer dependencies of `@icp-sdk/core` manually:
26+
>
27+
> ```shell
28+
> pnpm install @dfinity/agent @dfinity/candid @dfinity/identity @dfinity/identity-secp256k1 @dfinity/principal
29+
> ```
30+
2531
## CDN
2632
2733
We do not recommend using the CDN distribution of the `@icp-sdk/core` package for **production** applications.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: Library Development
3+
description: Guide for building libraries that depend on @icp-sdk/core
4+
sidebar:
5+
order: 4
6+
---
7+
8+
If you're building a library that depends on `@icp-sdk/core`, there are some specific considerations to ensure your library works correctly with bundlers and provides the best experience for your users.
9+
10+
## Bundler Configuration
11+
12+
### Rollup/Vite
13+
14+
When using Rollup or Vite (which uses Rollup under the hood), you need to specify each `@icp-sdk/core` submodule as an external dependency:
15+
16+
```js
17+
// rollup.config.js or vite.config.js
18+
export default {
19+
build: {
20+
rollupOptions: {
21+
external: [
22+
'@icp-sdk/core/agent',
23+
'@icp-sdk/core/candid',
24+
'@icp-sdk/core/identity',
25+
'@icp-sdk/core/identity/secp256k1',
26+
'@icp-sdk/core/principal',
27+
],
28+
output: {
29+
globals: {
30+
'@icp-sdk/core/agent': 'icp-sdk-core-agent',
31+
'@icp-sdk/core/candid': 'icp-sdk-core-candid',
32+
'@icp-sdk/core/identity': 'icp-sdk-core-identity',
33+
'@icp-sdk/core/identity/secp256k1': 'icp-sdk-core-identity-secp256k1',
34+
'@icp-sdk/core/principal': 'icp-sdk-core-principal',
35+
},
36+
},
37+
},
38+
},
39+
};
40+
```
41+
42+
## TypeScript Configuration
43+
44+
If your library is written in TypeScript, make sure your `tsconfig.json` uses compatible module resolution. See the [Typescript](./typescript.mdx) documentation for more details.

docs/src/content/docs/upgrading/v4.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ exported from a `@icp-sdk/core/*` submodule.
6464
+ import { HttpAgent } from '@icp-sdk/core/agent';
6565
```
6666

67-
## FAQ
67+
## Troubleshooting
6868

6969
### TypeScript `moduleResolution`
7070

@@ -115,3 +115,36 @@ The `@dfinity/use-auth-client` package is not included in `@icp-sdk/core` and **
115115

116116
- [ic-use-internet-identity](https://www.npmjs.com/package/ic-use-internet-identity)
117117
- [@ic-reactor/react](https://www.npmjs.com/package/@ic-reactor/react)
118+
119+
### Installing with pnpm
120+
121+
If you're using pnpm, you might need to install the peer dependencies of `@icp-sdk/core` manually:
122+
123+
```shell
124+
pnpm install @dfinity/agent @dfinity/candid @dfinity/identity @dfinity/identity-secp256k1 @dfinity/principal
125+
```
126+
127+
### Building libraries with Rollup/Vite
128+
129+
If you're building a library that depends on `@icp-sdk/core`, you need to specify each submodule you're using in your Rollup configuration (this also applies to Vite, which uses Rollup under the hood):
130+
131+
```js
132+
rollupOptions: {
133+
external: [
134+
'@icp-sdk/core/agent',
135+
'@icp-sdk/core/candid',
136+
'@icp-sdk/core/identity',
137+
'@icp-sdk/core/identity/secp256k1',
138+
'@icp-sdk/core/principal',
139+
],
140+
output: {
141+
globals: {
142+
'@icp-sdk/core/agent': 'icp-sdk-core-agent',
143+
'@icp-sdk/core/candid': 'icp-sdk-core-candid',
144+
'@icp-sdk/core/identity': 'icp-sdk-core-identity',
145+
'@icp-sdk/core/identity/secp256k1': 'icp-sdk-core-identity-secp256k1',
146+
'@icp-sdk/core/principal': 'icp-sdk-core-principal',
147+
},
148+
},
149+
},
150+
```

0 commit comments

Comments
 (0)