Closed stereokai closed 2 years ago
Vite would think new URL('./hello.js', import.meta.url)
is an asset so don't process it. And new Worker(new URL('./hello.js', import.meta.url))
is worker assets.
I think you want got a worker url for Vite, but now maybe can not.
@poyoho thanks for your reply :)
I think you want got a worker url for Vite, but now maybe can not.
It's not a maybe, it's a certain ;)
Do you think pull request #7706 will have ay effect?
no, it will make a dynamic import to be a chunk instead of worker assets.
This hacky workaround works. https://stackblitz.com/edit/vitejs-vite-a3lfsj?file=dist%2Fassets%2Fworker.68989bfb.js&terminal=dev
@sapphi-red Thanks a lot! Did you have a look at my use case (https://github.com/stereokai/vite-test)? Thanks
Sorry I meant a workaround to get a worker url.
I saw your repro now but I think it is almost working with my worker url workaround. Additionally, change workerpoolImport*
like below. It worked for me.
const workerpoolImportDev = `
importScripts("/node_modules/workerpool");
`;
let workerpoolImportProd;
try {
workerpoolImportProd = `
import workerpool from "workerpool";`;
} catch (e) {}
@sapphi-red thanks, though what do you mean exactly by almost working?
And can you please explain your change of workerpoolImport
?
@sapphi-red @poyoho Did you try out the test repo I set up? Thanks :)
Describe the bug
In a Vite project with some Rollup plugins, when importing a worker like this: new URL("./worker/CompiledWorker.js", import.meta.url).href, the inlined code doesn't get transformed through some plugins when running
vite build
. I tried setting the plugins both directly on Vite and also on Rollup. See repo.Reproduction
https://github.com/stereokai/vite-test
System Info
Used Package Manager
pnpm
Logs
Validations