From 57969361bb1610e42c236f158029592ba9fced4a Mon Sep 17 00:00:00 2001 From: Dawid Sowa Date: Thu, 23 Nov 2023 15:44:12 +0100 Subject: [PATCH 1/2] feat: allow asynchronous RDT instantiation --- src/connect-button/connect-button-client.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/connect-button/connect-button-client.ts b/src/connect-button/connect-button-client.ts index 6106bbf3..44d857ef 100644 --- a/src/connect-button/connect-button-client.ts +++ b/src/connect-button/connect-button-client.ts @@ -3,6 +3,7 @@ import { fromEvent, map, merge, + of, Subscription, switchMap, tap, @@ -44,7 +45,10 @@ export const ConnectButtonClient = (input: { const subscriptions = new Subscription() subscriptions.add( - fromEvent(document, 'onRender') + merge( + fromEvent(document, 'onRender'), + of(getConnectButtonElement()).pipe(filter((e) => !!e)) + ) .pipe( map(() => getConnectButtonElement()), filter((element): element is ConnectButton => !!element), From c63f38790f9b6b8ea31f9cc4fa7857827b41e475 Mon Sep 17 00:00:00 2001 From: Dawid Sowa Date: Thu, 23 Nov 2023 15:44:20 +0100 Subject: [PATCH 2/2] feat: add single file artifact --- package-lock.json | 19 ++++++++++++++++++- package.json | 5 +++-- src/single-file.js | 3 +++ vite-single-file.config.ts | 15 +++++++++++++++ 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 src/single-file.js create mode 100644 vite-single-file.config.ts diff --git a/package-lock.json b/package-lock.json index 688655b3..45e36ed9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -39,7 +39,8 @@ "ts-jest": "^29.0.5", "ts-node": "^10.9.1", "typescript": "^5.0.4", - "vite": "^4.3.5" + "vite": "^4.3.5", + "vite-plugin-singlefile": "^0.13.5" }, "engines": { "node": ">=16.0.0" @@ -7261,6 +7262,22 @@ } } }, + "node_modules/vite-plugin-singlefile": { + "version": "0.13.5", + "resolved": "https://registry.npmjs.org/vite-plugin-singlefile/-/vite-plugin-singlefile-0.13.5.tgz", + "integrity": "sha512-y/aRGh8qHmw2f1IhaI/C6PJAaov47ESYDvUv1am1YHMhpY+19B5k5Odp8P+tgs+zhfvak6QB1ykrALQErEAo7g==", + "dev": true, + "dependencies": { + "micromatch": "^4.0.5" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "peerDependencies": { + "rollup": ">=2.79.0", + "vite": ">=3.2.0" + } + }, "node_modules/w3c-xmlserializer": { "version": "4.0.0", "dev": true, diff --git a/package.json b/package.json index db144d8c..caf3fa90 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ ], "scripts": { "dev": "vite serve examples", - "build": "tsc && vite build", + "build": "tsc && vite build && vite build --config vite-single-file.config.ts", "prepare": "npx husky install", "test": "jest", "test:watch": "jest --watch" @@ -79,7 +79,8 @@ "ts-jest": "^29.0.5", "ts-node": "^10.9.1", "typescript": "^5.0.4", - "vite": "^4.3.5" + "vite": "^4.3.5", + "vite-plugin-singlefile": "^0.13.5" }, "repository": { "type": "git", diff --git a/src/single-file.js b/src/single-file.js new file mode 100644 index 00000000..8ff5c8bb --- /dev/null +++ b/src/single-file.js @@ -0,0 +1,3 @@ +import * as RadixDappToolkit from './index' + +export default RadixDappToolkit diff --git a/vite-single-file.config.ts b/vite-single-file.config.ts new file mode 100644 index 00000000..2bc7f56f --- /dev/null +++ b/vite-single-file.config.ts @@ -0,0 +1,15 @@ +import { defineConfig } from 'vite' +import { viteSingleFile } from 'vite-plugin-singlefile' + +export default defineConfig({ + plugins: [viteSingleFile()], + build: { + emptyOutDir: false, + lib: { + entry: 'src/single-file.js', + name: 'RDT', + fileName: 'radix-dapp-toolkit.bundle', + }, + }, + define: { 'process.env.NODE_ENV': '"production"' }, +})