Skip to content

Commit

Permalink
feat: Add a client "postinstall" bash script and initialization of wa…
Browse files Browse the repository at this point in the history
…sm from client. (#899)

This allows better scaling when multiple wasm files are used on the client
  • Loading branch information
msarcev authored Dec 7, 2023
1 parent 9d16570 commit a45e066
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ application-data
/api/.env
/api/logs/
/client/build
/client/public/iota_sdk_wasm_bg.wasm
/client/public/wasm

config.dev.json
config.local.json
Expand Down
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"license": "Apache-2.0",
"scripts": {
"postinstall": "copyfiles -u 5 ./node_modules/@iota/sdk-wasm/web/wasm/iota_sdk_wasm_bg.wasm ./public",
"postinstall": "./script/postinstall.sh",
"start": "vite",
"preview": "vite preview",
"lint": "eslint src --ext .tsx,.ts",
Expand Down
10 changes: 10 additions & 0 deletions client/script/postinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

NODE_MODULES="./node_modules"
TARGET="./public/wasm"

mkdir -p "$TARGET"

# stardust
cp "$NODE_MODULES/@iota/sdk-wasm/web/wasm/iota_sdk_wasm_bg.wasm" "$TARGET/iota_sdk_stardust_wasm_bg.wasm"

4 changes: 2 additions & 2 deletions client/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-argument */
// needed for features from @iota/sdk which use reflection (decorators)
import "reflect-metadata";
import init from "@iota/sdk-wasm/web";
import initStardustSdk from "@iota/sdk-wasm/web";
import React from "react";
import { createRoot } from "react-dom/client";
import { BrowserRouter, Route, RouteComponentProps } from "react-router-dom";
Expand Down Expand Up @@ -34,7 +34,7 @@ const apiEndpoint = (window as any).env.API_ENDPOINT;

initialiseServices().then(async () => {
// load the wasm
await init("/iota_sdk_wasm_bg.wasm");
await initStardustSdk("/wasm/iota_sdk_stardust_wasm_bg.wasm");

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const container = document.querySelector("#root")!;
Expand Down

0 comments on commit a45e066

Please sign in to comment.