-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
WebWorkers: Support new Worker( new URL() ) syntax #5430
Comments
Is there any official documentation for that? This special case ( parcel/packages/transformers/js/src/visitors/dependencies.js Lines 164 to 193 in cebbec7
|
As far as I can tell, not yet. Webpack 5 just released recently so it's a pretty new feature. |
This should also apply to the various worklets: #1093 |
So would the context be |
(These two should behave the same const worker = new Worker( new URL( './worker.js', import.meta.url ) ); // this issue
const worker = new Worker( './worker.js' ); // works already ) |
We should possibly drop the second syntax (what we currently support). In the browser, relative urls resolve from the page url not the script, so parcel currently doesn't match. |
In library builds, new Worker(new URL("./worker.js", import.meta.url)); should become new Worker(new URL("./worker.af82942.js", import.meta.url)); |
This has been supported for a while. |
In case anyone is wondering about the new syntax for the webworker I found something here: parcel-bundler/parcel#5430
🙋 feature request
As of v5 Webpack has introduced support for WebWorkers with the following syntax:
This is the right way to load a Worker with a relative path from a module. However this doesn't work in Parcel. It would be great if parcel supported this for Workers (or parsing new URL in general) to support this use case so packages can be written and used consistently across bundlers.
🤔 Expected Behavior
The following should instantiate a new Worker next to the current module file.
😯 Current Behavior
The worker is loaded from the wrong path.
💁 Possible Solution
Account for
new URL( <path>, import.meta.url )
when processing Workers.🔦 Context
My valid, browser-runnable code cannot be built with Parcel but can be built with Webpack. I would like to be able to write code that works consistently across browsers and bundlers.
The text was updated successfully, but these errors were encountered: