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

importScripts #104

Closed
OhFlohre opened this issue Jun 27, 2020 · 3 comments
Closed

importScripts #104

OhFlohre opened this issue Jun 27, 2020 · 3 comments
Labels
question Further information is requested

Comments

@OhFlohre
Copy link

is there a way to use the WorkerGlobalScope.importScripts() method with workerize-loader?

@DronHazra
Copy link

I'd like to know this too

@wclr
Copy link

wclr commented Aug 13, 2020

why not self.importScripts?

@developit
Copy link
Owner

developit commented Jan 9, 2021

Indeed - the existence of importScripts just depends on how you load the module. If it's a Classic Worker (new Worker(url)), importScripts() should work fine. If it's a Module Worker (new Worker(url, {type:'module'})), you'll want to use import() instead.

Read more here: https://web.dev/module-workers/

(I get the impression this question was prompted by TypeScript making it seem like importScripts() isn't defined - TypeScript doesn't know that you're in a Worker context unless you tell it you are, which requires moving your worker code into a directory with its own tsconfig.js that replaces DOM typings with Worker ones. It's... a rough edge)

@developit developit added the question Further information is requested label Jan 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants