Open gpoitch opened 6 years ago
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.
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.
yup yup.
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.Could it be adapted to be more generic or am I missing something specific this does for web workers?