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

[question] Support service workers? #7

Open
gpoitch opened this issue Oct 1, 2018 · 3 comments
Open

[question] Support service workers? #7

gpoitch opened this issue Oct 1, 2018 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@gpoitch
Copy link

gpoitch commented Oct 1, 2018

I know this is specific to web workers, however I think this could be adapted to work for service workers. I was looking to create a separate plugin but the code would be mostly the same.

Looks like it scans the AST for a keyword (Worker) and generates an entry for the referenced file.

// web worker
new Worker('./foo.js', { type: 'module' })

// service worker
navigator.serviceWorker.register('./foo.js', { type: 'module' })

Could it be adapted to be more generic or am I missing something specific this does for web workers?

@developit
Copy link
Collaborator

That's a great idea! It's definitely an option. I wonder if there's a larger question here of "script entry points" - *Worklet addModule() would be another that would fit nicely into here.

One tricky bit is actually ensuring .register() is invoked on a real instance of ServiceWorkerContainer, versus just a local variable of that name. Perhaps that's a reason to test out only supporting navigator.serviceWorker.register() and not other module entry points, since it's a pretty specific name that is unlikely to be miscategorized.

@developit developit added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Oct 8, 2018
@gpoitch
Copy link
Author

gpoitch commented Oct 8, 2018

Great, good to know! I'd love a plugin (or for webpack proper) to support generating assets for any kind of script url APIs. Figured your name worker-plugin could get away with at least adding service workers too.

Good point about variablizing. I guess the current setup would also fail if someone did const W = Worker; new W('./foo') but that wouldn't be as likely. Could just be a note in the readme about it.

@developit
Copy link
Collaborator

yup yup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants