-
-
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: allow custom worker #2578
Conversation
done @Shinigami92 |
Hey @dejour! Thank you for working on this. This PR misses TypeScript support. Currently // web worker
declare module '*?worker' {
const workerConstructor: {
new (): Worker
}
export default workerConstructor
}
declare module '*?worker&inline' {
const workerConstructor: {
new (): Worker
}
export default workerConstructor
} It means that TSC won't recognize import with additional parameters. Is it not possible to implement this functionality without augmenting the import statement? Here is what I mean: import MyWorker from './worker?worker'
const worker = new MyWorker() // classic worker
const worker = new MyWorker({type: 'classic'}) // classic worker
const worker = new MyWorker({type: 'module'}) // module worker |
And I couldn't make it work with classic worker. // main
import MyWorker from './worker?worker&type=classic';
const worker = new MyWorker();
console.log({ worker }); // worker.ts
importScripts('www.gstatic.com/firebasejs/8.0.0/firebase-app.js') // use importScripts to verify classic-ness
console.log(`worker here`, { firebase: firebase }) The generated worker file looks like this: import '/@fs/Users/evgenijbeloded/Code/vendors/vite-classic-workers/packages/vite/dist/client/env.js'
importScripts("www.gstatic.com/firebasejs/8.0.0/firebase-app.js");
console.log(`ts worker here`, {firebase}); Which rightfully stumbles on the first line with SyntaxError:
|
it seems possible.
import statement can only be used in module worker, this indeed is a problem needed to be fixed. if not augmenting the import statement, we can not change the way env.js is imported. |
Is this PR abandoned? |
This PR offers a solution to #2550.