From 0a1f246679d5eeabad30c453574932a37a30fc70 Mon Sep 17 00:00:00 2001 From: John Edvard Reiten Date: Wed, 17 Aug 2022 22:06:11 +0900 Subject: [PATCH] chore: Remove prebuild command Prebuild was messing up the dev server, but I do not know why --- package.json | 1 - src/index.html | 7 +------ src/index.js | 20 +++++++++++++++++--- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index a9bcbd7..968efad 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,6 @@ "source": "src/index.html", "scripts": { "start": "parcel serve", - "prebuild": "rm -rf dist", "build": "parcel build src/index.html" }, "author": "johnedvard", diff --git a/src/index.html b/src/index.html index 0e7917d..2b018fc 100644 --- a/src/index.html +++ b/src/index.html @@ -4,15 +4,10 @@ Skeleton rope - - - + diff --git a/src/index.js b/src/index.js index edd60db..46429f6 100644 --- a/src/index.js +++ b/src/index.js @@ -7,9 +7,23 @@ const init = () => { }; const initNear = () => { - const nearConnection = new NearConnection(); - nearConnection.initContract().then((res) => { - initLoginLogout(nearConnection); + loadNearApi().then(() => { + const nearConnection = new NearConnection(); + nearConnection.initContract().then(() => { + initLoginLogout(nearConnection); + }); + }); +}; + +const loadNearApi = () => { + return new Promise((resolve) => { + if (window.nearApi) resolve(); + const script = document.createElement('script'); + script.onload = () => { + resolve(); + }; + script.src = 'https://js13kgames.com/src/near-api-js.js'; + document.head.appendChild(script); }); };