-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
support ?inline
worker in constructors worker
#7352
Comments
how about use the if (content.length < Number(config.build.assetsInlineLimit))) {
const encodedJs = "${code.toString('base64')}"
} |
I'm not sure what's the usecase for inlining workers yet, but I like the option with |
config in worker options |
{
worker?: {
/**
* Output format for worker bundle
* @default 'iife'
*/
format?: 'es' | 'iife'
/**
* Vite plugins that apply to worker bundle
*/
plugins?: (PluginOption | PluginOption[])[]
/**
* Rollup options to build worker bundle
*/
rollupOptions?: Omit<
RollupOptions,
'plugins' | 'input' | 'onwarn' | 'preserveEntrySignatures'
>
/**
* Worker files smaller than this number (in bytes) will be inlined as
* base64 strings. Default limit is `4096` (4kb). Set to `0` to disable.
* @default 4096
*/
inlineLimit?: number,
}
} |
I have also seen suggestions for this configuration before, such as judging whether it should be inline by the file name |
I don't know either (limit requests?) but then just switch to http2. The only use case I can think of if you want to inline ALL workers. (When you want a single file so evrything is potentaly inlined into the html file)
|
Hi, any bump on this? looking for solution how to inline worker for an npm package |
@antokhio Why do you want them inline? |
https://discord.com/channels/804011606160703521/1040565505003618354 This is the discussion. So when I build package I have worker script bundled to /assets. Then I install this package with yarn or npm, add my component, check the chrome xhr and I see my worker script unavailable… Already spent few days on that and I’m starting to think that the only way is to expose worker script and add is a dep to a worker manager class constructor that I’m using… ps. If I copy worker bundle .js to public folder of new project it works… |
This is a bit strange but: // doesn't work:
const getWorker = () => new Worker(new URL('./worker.js', import.meta.url), { type: 'module' })
// works:
const url = new URL('./worker.js', import.meta.url)
const getWorker = () => new Worker(url, { type: 'module' }) The first code example is handled by the internal |
hi @jonaskuske so i change the code and now it seems it's add another error hmm: const url = new URL('./workers/arnft.worker.ts', import.meta.url);
const getWorker = () => new Worker(url, { type: 'module' });
const worker = getWorker() as Worker; results: const url = new URL("data:video/mp2t;base64,aW1...=", self.location);
const getWorker = () => new Worker(url, { type: "module" });
const worker = getWorker(); I think i've seen another issue with this trying to resolve from comments |
@antokhio
I think there was a way to change how worker / import.meta.url are emitted... That would be a solution for your problem. Default is: const w = new Worker(
new URL("/assets/worker.5ac1100d.js", self.location),
{
type: "module"
}
); |
@mathe42 that's what i have right now in the build: const worker = new Worker(new URL("/arnft.worker.4e733d5c.js", self.location), {
type: "module"
}); Ahhh got it finnaly: the correct ts syntax: const worker = new Worker(new URL('./workers/arnft.worker.ts', import.meta.url), { type: 'module', }) as Worker; thanks @jonaskuske @mathe42 |
Did not fix that for me in build. What is the rest of your vite-config? |
i think this isn't fixed ((( i had a worker script copied to public on tester project, that's why it worked |
Will have a deeper look into it later. |
did we come to a conclusion on this by any chance? running into the same issue defined here |
Any update on this? |
Yea, still haven't managed to fix my package... |
Clear and concise description of the problem
we can use inline worker with
import worker from "./worker?worker&inline"
and need to support inline worker in constructors worker.
Suggested solution
but the end goal is to remove query suffixes everywhere for Vite.
that's non-standard
and Rollup has a history of avoiding that too (e.g. webpackChunkName) and only supported pure comments thus far.
above solutions are not good.
this issue for it to discussed some ideas ❤️
Alternative
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: