This is an experimental plugin, not intended for production.
Use workers without thinking about using workers.
It transforms your importetd file with an .worker. extension to wrap around a Comlink Proxy, without braking any types.
// vite.config.ts
import wrapWorker from "@luckydye/vite-wrap-worker";
import { defineConfig } from "vite";
export default defineConfig({
base: "",
plugins: [wrapWorker()],
});
// Process.worker.ts
export default {
async work() {
console.log("done", globalThis);
},
};
// main.ts
import Process from "./Process.worker";
await Process.work()
// done, DedicatedWorkerGlobalScope