From 5514e00b7a33326543336260faa1ce08d8c29bdb Mon Sep 17 00:00:00 2001 From: Zee Spencer Date: Thu, 22 Feb 2018 08:52:11 -0800 Subject: [PATCH] Support `load` plugin in node Relying on `Gun` being globally available is not valid in most cases where a module loader is being used to import the `load` plugin. Instead, pull `Gun` from window if window is defined, otherwise require it using the module loader. --- lib/load.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/load.js b/lib/load.js index 233c8c09..f34f9ca5 100644 --- a/lib/load.js +++ b/lib/load.js @@ -1,4 +1,8 @@ -var Gun = Gun || require('../gun'); +if(typeof window !== "undefined"){ + var Gun = window.Gun; +} else { + var Gun = require('gun/gun'); +} Gun.chain.open || require('gun/lib/open'); Gun.chain.load = function(cb, opt, at){