Repository navigation
new Worker() support - #11439
new Worker() support#11439
Conversation
|
For maintainers only:
|
add support for async anonymous entrypoints from inside the codebase add worker example move entry options into Entrypoint and receive them from there
57962d9 to
ed06a7f
Compare
|
Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon. |
|
@sokra may I suggest to document the following too? How can you create those?
|
|
|
@sokra is
How do I create an async entrypoint from code? Next.js' interactive won't offload scripts to a worker |
This is a WebWorker thing. That's not directly related to For
|
|
I've created an issue to document this in webpack/webpack.js.org. |
|
@sokra I might suggest avoiding using raw |
|
@developit |
|
webpack doesn't care a lot about the exact API. It only uses |
|
Right - currently it would not work because of the source check when Worker is an imported identifier. @evilebottnawi I know, my point was that this makes it impossible to write code that supports both web and node. |
|
I'll add this: module.rules: [
{
test: /\.[cm]?js$/,
parser: {
worker: ["...", "default from web-worker"]
}
}
]
[
"Worker",
"SharedWorker",
"navigator.serviceWorker.register()",
"Worker from worker_threads"
] |
|
Hi @sokra, First of all thanks for this awesome feature, it's really nice to have it available out of the box! One question though, is it possible to use something else than |
|
@yamafaktory What do you want to use? This syntax works on node and browsers, without |
|
@evilebottnawi that's exactly what I want to highlight here. Depending on the loader you use and the target, |
|
You can use any |
|
Ok, thanks for the feedback! |
|
I think it's not possible to use this feature without import.meta. As workaround use something different and chain the esbuild-loader with the string-replace-loader and replace that with import.meta |
|
@sokra thanks for the feedback, this sounds like a viable approach indeed! How do you inject back import.meta? Is it somehow exposed by Webpack? |
|
This new way of handling workers is simple, saves a worker loading plugin, and is far more intuitive. I'm working on a project that ships a library to consumers which means that more often than not, the worker sits on a CDN on some other origin. I've skimmed the source code and it doesn't look immediately possible to add new worker import strategies. But I wonder: is there a plugin available for adding fetch support? If no, how would I go about writing one? |
This adds support to create entrypoints from AsyncDependenciesBlocks. Might also be useful for other scenarios (@timneutkens
interactive)What kind of change does this PR introduce?
feature
Did you add tests for your changes?
yes
Does this PR introduce a breaking change?
yes
What needs to be documented once your changes are merged?
ouput.workerChunkLoadingcontrols the chunk loading of workers (default chosen based onoutput.chunkLoading)ouput.workerChunkLoadingas chunk loading mechnismnew Worker(new URL("...", import.meta.url), ...)with optionalimport { Worker } from "worker_threads"navigator.serviceWorker.register(new URL("...", import.meta.url), ...)