-
Allow importing classic Web Workers (not Module Workers) . 目前的解决方案看起来是 Import with Constructors,但是加入我的worker 文件是 typescript怎么办呢?是需要提前编译好吗? 编译后是这样子的,是需要额外配置什么吗? new URL("./worker.ts", import.meta.url)
// after npm run build
const ng=new URL("./worker.ts",self.location);Yr=new Worker(ng,{type:"classic"}); feat(worker): allow passing options to worker constructors 这个方案挺好的,但是目前是被上面的方案替换掉了 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
补充下,加入是这种形式 就可以正常编译了。
那当下的问题就是 developer 的 env mode 下,我使用用 classic ,会出现错误, 所以 我不得不判断一些是不是在 开发模式下... 做一些特殊的处理 最初是这样子做的, let worker: Worker;
if (import.meta.env.DEV) {
worker = new Worker(new URL("./worker/rcdata", import.meta.url), {
type: "module",
});
} else {
worker = new Worker(new URL("./worker/rcdata", import.meta.url), {
type: "classic",
});
} 但是感觉
应该是 new worker(new url...) 有特殊的处理方式吧... |
Beta Was this translation helpful? Give feedback.
-
In vite, we preset |
Beta Was this translation helpful? Give feedback.
In vite, we preset
new worker(new URL(...))
as a static string. if the first parameter of the new worker is a variable, it cannot be analyzed. Maybe you can useimport workerURL from "./worker?worker&url"
and use the worker URL the create worker