Skip to content

Commit 10eccd7

Browse files
committed
Update Vite integration docs with plugin
1 parent ea0804c commit 10eccd7

File tree

1 file changed

+60
-30
lines changed

1 file changed

+60
-30
lines changed

web-client/integrations/vite.md

Lines changed: 60 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,67 +20,97 @@ cd my-nimiq-app && pnpm install && pnpm dev
2020

2121
## Installation
2222

23-
### Quick Start
24-
25-
Install the Nimiq Web Client and required Vite plugins:
23+
Install the Nimiq Web Client:
2624

2725
::: code-group
2826

2927
```bash [pnpm]
3028
pnpm add @nimiq/core
31-
pnpm add -D vite-plugin-top-level-await vite-plugin-wasm
3229
```
3330

3431
```bash [npm]
3532
npm install @nimiq/core
36-
npm install -D vite-plugin-top-level-await vite-plugin-wasm
3733
```
3834

3935
```bash [yarn]
4036
yarn add @nimiq/core
41-
yarn add -D vite-plugin-top-level-await vite-plugin-wasm
4237
```
4338

4439
```bash [bun]
4540
bun add @nimiq/core
46-
bun add -D vite-plugin-top-level-await vite-plugin-wasm
4741
```
4842

4943
:::
5044

5145
## Configuration
5246

53-
### Basic Vite Setup
47+
The Nimiq Web Client includes a Vite plugin that automatically configures WebAssembly support and all required optimizations.
48+
49+
> [!TIP]
50+
> View the [plugin source code](https://github.com/nimiq/core-rs-albatross/blob/main/web-client/dist/vite.js) for implementation details.
51+
52+
Update your `vite.config.ts`:
53+
54+
```ts [vite.config.ts]
55+
import nimiq from '@nimiq/core/vite' // [!code ++]
56+
import { defineConfig } from 'vite'
57+
58+
export default defineConfig({
59+
plugins: [nimiq()], // [!code ++]
60+
})
61+
```
62+
63+
The plugin automatically configures:
64+
- WebAssembly support with `vite-plugin-wasm`
65+
- Worker configuration for WASM modules
66+
- Build target optimizations (`esnext`)
67+
- Dependency exclusions for `@nimiq/core`
68+
69+
<details>
70+
<summary>Legacy Browser Support</summary>
71+
72+
Modern browsers (Chrome 89+, Firefox 89+, Safari 15+, Edge 89+) support top-level await natively. If you need to support older browsers, install `vite-plugin-top-level-await`:
73+
74+
::: code-group
75+
76+
```bash [pnpm]
77+
pnpm add -D vite-plugin-top-level-await
78+
```
79+
80+
```bash [npm]
81+
npm install -D vite-plugin-top-level-await
82+
```
5483

55-
Update your `vite.config.js` or `vite.config.ts`:
84+
```bash [yarn]
85+
yarn add -D vite-plugin-top-level-await
86+
```
5687

57-
```javascript
88+
```bash [bun]
89+
bun add -D vite-plugin-top-level-await
90+
```
91+
92+
:::
93+
94+
Then add it to your Vite config:
95+
96+
```ts [vite.config.ts]
97+
import nimiq from '@nimiq/core/vite'
5898
import { defineConfig } from 'vite'
59-
import wasm from 'vite-plugin-wasm' // [!code ++]
99+
import topLevelAwait from 'vite-plugin-top-level-await' // [!code ++]
60100
61101
export default defineConfig({
62-
plugins: [wasm()], // [!code ++]
63-
worker: { // [!code ++]
64-
format: 'esnext', // [!code ++]
65-
plugins: () => [wasm()], // [!code ++]
66-
}, // [!code ++]
67-
68-
optimizeDeps: { // [!code ++]
69-
exclude: ['@nimiq/core'], // [!code ++]
70-
}, // [!code ++]
71-
72-
// Additional build configuration for Nimiq // [!code ++]
73-
build: { // [!code ++]
74-
target: 'esnext', // [!code ++]
75-
rollupOptions: { // [!code ++]
76-
output: { // [!code ++]
77-
format: 'esnext', // [!code ++]
78-
}, // [!code ++]
79-
}, // [!code ++]
80-
}, // [!code ++]
102+
plugins: [
103+
nimiq(),
104+
topLevelAwait(), // [!code ++]
105+
],
81106
})
82107
```
83108

109+
> [!NOTE]
110+
> Top-level await is required for ES modules when using dynamic WASM imports. The plugin transforms top-level await to work in older browsers.
111+
112+
</details>
113+
84114
## Usage Example
85115

86116
<!--@include: ../_demo.web.md-->

0 commit comments

Comments
 (0)