-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Add cross-origin worker support #14680
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
Closed
piotr-oles
wants to merge
10
commits into
webpack:main
from
piotr-oles:feature/add-worker-cross-origin-loading-option
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
db57dc3
Add tests cases for cross-origin web workers
piotr-oles 2a78b9f
Add `workerCrossOriginLoading` option to webpack config
piotr-oles b3b628c
Add support for cross-origin workers
piotr-oles 8be1090
Update `createFakeWorker` to be compatible with dynamic public path
piotr-oles 076d758
Add missing description to `workerCrossOriginLoading` option
piotr-oles cdc3b82
Fix types issues
piotr-oles 0323ffc
Update snapshots
piotr-oles a7eacc9
Refactor cross-origin support implementation
piotr-oles 30918be
Update snapshots
piotr-oles 20d56b1
Add support for ES Modules for cross origin workers
piotr-oles File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| MIT License http://www.opensource.org/licenses/mit-license.php | ||
| */ | ||
|
|
||
| "use strict"; | ||
|
|
||
| const RuntimeGlobals = require("../RuntimeGlobals"); | ||
| const Template = require("../Template"); | ||
| const HelperRuntimeModule = require("./HelperRuntimeModule"); | ||
|
|
||
| class CreateScriptBlobRuntimeModule extends HelperRuntimeModule { | ||
| constructor() { | ||
| super("create script blob"); | ||
| } | ||
|
|
||
| /** | ||
| * @returns {string} runtime code | ||
| */ | ||
| generate() { | ||
| const { compilation } = this; | ||
| const { runtimeTemplate } = compilation; | ||
| const fn = RuntimeGlobals.createScriptBlob; | ||
|
|
||
| return Template.asString([ | ||
| `${fn} = ${runtimeTemplate.basicFunction("code", [ | ||
| "try {", | ||
| Template.indent( | ||
| `return URL.createObjectURL(new Blob([code], { type: "application/javascript" }));` | ||
| ), | ||
| `} catch (e) {`, | ||
| Template.indent( | ||
| `return new URL("data:application/javascript," + encodeURIComponent(code));` | ||
| ), | ||
| "}" | ||
| ])}` | ||
| ]); | ||
| } | ||
| } | ||
|
|
||
| module.exports = CreateScriptBlobRuntimeModule; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure it is good solution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you elaborate?
Is it bad because of the runtime implementation?
Are you concerned about browser support?
Or is it bad because of how it interact with webpack architecture?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Firstly, we need to add
blobsupport tohttps://github.com/webpack/webpack/blob/main/lib/config/target.js#L81, we don't need to generate extra runtime if developer provide versions.I think we need to look at this solution a little differently,
blobloading can be added not only for workers, any file can be loaded usingblob, yes it is most often applicable to workers, but if we need to add blob support we need to add them to any types - js/web wokrers/asset modules and provide option to this.crossOriginLoadingis some misleading, you apply several techniques that can be applied to other things to solve the cross origin problem. For example you can applybase64here too.I see what you want to solve and what problem you are experiencing, but I think we should think it over in more detail
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already support
asset/raw, so we can haveasset/bloband refactor runtime to allow using it onjavascriptfiles, so you can loaded bundled file as raw text or as blob (just idea)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... That's interesting, I agree that we should try to generalise the use-case.
On the other hand, we don't load the file using Blob - we only use it to create
importScripts(filePath)code (and the file itself is loaded later by the runtime).So this wouldn't work with other file types. Do you suggest adding
asset/bloband then emitting the "importScripts(filePath)" file and importing it usingasset/blob?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In some sense it's already possible - I do this here (it could be extracted to a plugin).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sokra What do you think about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sokra bump.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My team is desperate for this to be merged. We need cross-origin workers, and
worker-loaderis causing all kinds of problems. Is there any way that generalizing custom public paths can be deferred until after this feature is merged? If I can assist in development or testing in any way, I am happy to offer my attention and energy.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AprilArcus
You can use a shim in the meantime that @piotr-oles created here
Works great for me. Although, I'm in the same boat because I want to have 2 separate builds for varying purposes.
Would be happy to add support where I can. @alexander-akait - is there anyone else that could take a look?