Skip to content

Commit f0b1cb7

Browse files
onmaxjsdanielh
authored andcommitted
Add Vite plugin export
1 parent 0ee9a43 commit f0b1cb7

4 files changed

Lines changed: 90 additions & 1 deletion

File tree

web-client/dist/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ If you use any bundler for your project, like Webpack or Vite, you should probab
2626

2727
For detailed installation instructions for your bundler/framework, refer to the [Nimiq Developer Center](https://www.nimiq.com/developers/build/web-client/installation).
2828

29+
> [!TIP]
30+
> **For Vite**: Use the included Vite plugin for automatic configuration:
31+
>
32+
> ```ts
33+
> import nimiq from "@nimiq/core/vite";
34+
>
35+
> export default defineConfig({
36+
> plugins: [
37+
> nimiq(),
38+
> ],
39+
>});
40+
> ```
41+
2942
```js
3043
// With Webpack: import the package asynchronously:
3144
const Nimiq = await import('@nimiq/core');

web-client/dist/package.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
"browser": "./web/index.js",
2727
"import": "./web/index.js",
2828
"types": "./types/web.d.ts"
29+
},
30+
"./vite": {
31+
"import": "./vite.js",
32+
"require": "./vite.js",
33+
"types": "./types/vite.d.ts"
2934
}
3035
},
3136
"homepage": "https://nimiq.com",
@@ -51,6 +56,15 @@
5156
],
5257
"dependencies": {
5358
"comlink": "^4.4.1",
54-
"websocket": "^1.0.34"
59+
"websocket": "^1.0.34",
60+
"vite-plugin-wasm": "^3.5.0"
61+
},
62+
"peerDependencies": {
63+
"vite": ">=5.0.0"
64+
},
65+
"peerDependenciesMeta": {
66+
"vite": {
67+
"optional": true
68+
}
5569
}
5670
}

web-client/dist/types/vite.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { PluginOption } from 'vite'
2+
3+
export interface NimiqPluginOptions {
4+
/**
5+
* Configure worker support for WASM
6+
* @default true
7+
*/
8+
worker?: boolean
9+
}
10+
11+
/**
12+
* Vite plugin for Nimiq blockchain integration
13+
* Configures WebAssembly support and optimizations required for @nimiq/core
14+
*/
15+
export default function nimiq(options?: NimiqPluginOptions): PluginOption[]
16+
17+
export { nimiq }

web-client/dist/vite.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import wasm from 'vite-plugin-wasm'
2+
3+
/**
4+
* Vite plugin for Nimiq blockchain integration
5+
* Configures WebAssembly support and optimizations required for @nimiq/core
6+
*
7+
* Note: This plugin does not include top-level await support. Modern browsers
8+
* support top-level await natively. If you need support for older browsers,
9+
* you can add vite-plugin-top-level-await to your plugins.
10+
*
11+
* @param {object} [options] - Plugin options
12+
* @param {boolean} [options.worker=true] - Configure worker support for WASM
13+
* @returns {import('vite').Plugin[]} Array of Vite plugins
14+
*/
15+
export default function nimiq({ worker = true } = {}) {
16+
return [
17+
wasm(),
18+
{
19+
name: 'vite-plugin-nimiq',
20+
config() {
21+
return {
22+
optimizeDeps: {
23+
exclude: ['@nimiq/core'],
24+
},
25+
build: {
26+
target: 'esnext',
27+
rollupOptions: {
28+
output: {
29+
format: 'es',
30+
},
31+
},
32+
},
33+
...(worker && {
34+
worker: {
35+
format: 'es',
36+
plugins: () => [wasm()],
37+
},
38+
}),
39+
}
40+
},
41+
},
42+
]
43+
}
44+
45+
export { nimiq }

0 commit comments

Comments
 (0)