Skip to content

Commit 1863a9b

Browse files
committed
Add vite-plugin-nimiq package
1 parent a37c5d6 commit 1863a9b

File tree

19 files changed

+2337
-355
lines changed

19 files changed

+2337
-355
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# vite-plugin-nimiq
2+
3+
Vite plugin for Nimiq blockchain integration with WebAssembly support.
4+
5+
## Installation
6+
7+
```bash
8+
pnpm add -D vite-plugin-nimiq
9+
```
10+
11+
## Usage
12+
13+
```typescript
14+
import { defineConfig } from 'vite'
15+
import nimiq from 'vite-plugin-nimiq'
16+
17+
export default defineConfig({
18+
plugins: [nimiq()],
19+
})
20+
```
21+
22+
## What it does
23+
24+
- Configures WebAssembly support via `vite-plugin-wasm`
25+
- Excludes `@nimiq/core` from dependency optimization
26+
- Sets ESNext target and ES modules output
27+
- Configures Web Workers with WASM support
28+
29+
## License
30+
31+
MIT
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "vite-plugin-nimiq",
3+
"type": "module",
4+
"version": "0.0.1",
5+
"description": "Vite plugin for Nimiq blockchain integration with WebAssembly support",
6+
"author": "Nimiq",
7+
"license": "MIT",
8+
"repository": {
9+
"type": "git",
10+
"url": "git+https://github.com/onmax/nimiq-starter.git",
11+
"directory": "packages/vite-plugin-nimiq"
12+
},
13+
"keywords": [
14+
"vite",
15+
"vite-plugin",
16+
"nimiq",
17+
"blockchain",
18+
"webassembly",
19+
"wasm"
20+
],
21+
"exports": {
22+
".": {
23+
"types": "./vite.d.ts",
24+
"import": "./vite.js",
25+
"require": "./vite.js"
26+
}
27+
},
28+
"main": "./vite.js",
29+
"module": "./vite.js",
30+
"types": "./vite.d.ts",
31+
"files": [
32+
"vite.d.ts",
33+
"vite.js"
34+
],
35+
"peerDependencies": {
36+
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
37+
},
38+
"dependencies": {
39+
"vite-plugin-wasm": "^3.5.0"
40+
},
41+
"devDependencies": {
42+
"vite": "^7.1.7"
43+
}
44+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { Plugin } from 'vite'
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 array manually.
10+
*
11+
* @returns Array of Vite plugins
12+
*/
13+
export default function nimiq(): Plugin[]
14+
15+
export { nimiq }

packages/vite-plugin-nimiq/vite.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 array manually.
10+
*
11+
* @returns {import('vite').Plugin[]} Array of Vite plugins
12+
*/
13+
export default function nimiq() {
14+
return [
15+
wasm(),
16+
{
17+
name: 'vite-plugin-nimiq',
18+
config() {
19+
return {
20+
optimizeDeps: {
21+
exclude: ['@nimiq/core'],
22+
},
23+
build: {
24+
target: 'esnext',
25+
rollupOptions: {
26+
output: {
27+
format: 'es',
28+
},
29+
},
30+
},
31+
worker: {
32+
format: 'es',
33+
},
34+
}
35+
},
36+
configResolved(config) {
37+
// Vite ignores worker.plugins from config() hook, so we inject it here
38+
// This ensures WASM support works in Web Workers during build
39+
if (!config.worker.plugins) {
40+
config.worker.plugins = []
41+
}
42+
43+
// Check if wasm plugin is already present to avoid duplicates
44+
const hasWasmPlugin = config.worker.plugins.some(
45+
p => p && (p.name === 'vite:wasm' || p.name === 'wasm'),
46+
)
47+
48+
if (!hasWasmPlugin) {
49+
config.worker.plugins.push(wasm())
50+
}
51+
},
52+
},
53+
]
54+
}
55+
56+
export { nimiq }

0 commit comments

Comments
 (0)