-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
feat: worker format with worker type #8488
base: main
Are you sure you want to change the base?
Conversation
I fear this may be going too far. Is there a way to support the use case without exposing this? |
@patak-dev is need to output two format chunks? In fact, two workers can be exported, and users can choose what they like. The remaining workers will generate files but have no code at runtime(clean it by tree-sharking) // when config `worker.format: all`
export function esmWorkerWrapper() {
return new Worker(url)
}
export function iifeWorkerWrapper() {
return new Worker(url2)
} The disadvantage is that it need to build a worker twice and emit the unused worker |
I think the url options we can replace like this import worker, { url } from "./worker.js?worker" worker.js?worker export const url = "..."
export default function WorkerWrapper() {
return new worker("url", {type: "module"})
} |
And use this plan to judge whether the worker needs to be an inline worker #7352 (comment) |
Would you expand a bit more on the proposed changes in your last comments? |
now I think we can remove all current url query, and then make the content of the url query export by default. (rollup tree-sharking can remove the extra content.)
I think the url query syntax we provide is best to have only one level, and the others are exported by default through the virtual module. now it seems just worker work combine multiple query options. 😁 |
Oh, I see, that is an interesting idea. Maybe something to explore in v4 once we also remove the query in favor of |
I think index.css will like this. export const inline = 'css code'
export default 'css url' in v2 we import the internal module like import indexCSSURL from "./index.css"
import indexCSSRaw from "./index.css?inline"
import worker from "./worker?worker"
import workerURL from "./worker?worker&url"
import inlineWorker from "./worker?worker&inline" in v3 import indexCSSURL ,{ inline as indexCSSRaw } from "./index.css"
import { url as workerURL, inline }, worker from "./worker?worker" However, a big problem is that these strings are stored in memory, which may occupy a very large memory |
This one won't work because when you use the |
oh, I see. |
But now it seems that url, raw, inline are virtual modules based on vite, and they remain as they are, which is easier for users to accept. IIUC, your suggestion is according to the worker type we collected to interpret the format mode. |
This reverts commit cfb8966.
Related here is: #7163 I'd love the ability to just get the URL and format for a another bundle. The annoying thing about the current v2 API today is that I cannot easily reuse it for a service worker, because the URL is hidden. |
Description
fix: #8466
Additional context
import worker from worker.js?worker&format=esm
import worker from worker.js?worker&format=iife
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).