Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup without build tools #1363

Closed
zzph opened this issue Jan 31, 2024 · 3 comments
Closed

Setup without build tools #1363

zzph opened this issue Jan 31, 2024 · 3 comments

Comments

@zzph
Copy link

zzph commented Jan 31, 2024

Hi there,

I’m trying to integrate using this within a Chrome Extension as part of a service worker.

  • From this repo, create a minified build of the latest version of gun.js
  • Put that minified file into my project, then import it in my service worker as ‘var gun = importScripts(“./gun.js”)’

I get the welcome message (“Hello wonderful person...”), but I cannot use the library as "gun" is undefined.

Without build tools, what's the correct way to import/use this library?

Ps brilliant work on this @amark !

@zzph zzph changed the title Basic setup: using importScript (no npm) Setup without build tools Jan 31, 2024
@amark
Copy link
Owner

amark commented Feb 4, 2024

I believe @bmatusiak has a fix for this in github master, not in npm yet, but you can manually shim meanwhile if you want for serviceworkers by doing window = self before import I think. Sorry!

THanks!

@bmatusiak
Copy link
Collaborator

bmatusiak commented Aug 17, 2024

importScripts(“./gun.js”)’ only imports script into context, doesn't return anything , sometimes except for the last declared variable in the scripts global scope..

quite possible that globalThis.GUN or globalThis.Gun or gloabl.GUN or gloabl.Gun exist

Require and importScript are both functions used to include modules in JavaScript files:

Require

Part of the CommonJS module system, require is used in Node.js for server-side development. It can be called from anywhere in the program, and it returns an object. Require is dynamic, meaning it loads modules during runtime, so it can be used conditionally. For example, you can use require inside conditions or functions.

ImportScript

Part of web workers, importScript loads additional code, but it pauses execution of the worker to fetch and evaluate each script. It executes scripts in the global scope, similar to a <script> tag, so variables in one script can overwrite others.

@bmatusiak
Copy link
Collaborator

closing this for now.. please re-open if your still having issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants