Skip to content
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

fix: worker 需要有自己的 runtime #605

Closed
jiesia opened this issue Oct 31, 2023 · 3 comments · Fixed by #755
Closed

fix: worker 需要有自己的 runtime #605

jiesia opened this issue Oct 31, 2023 · 3 comments · Fixed by #755

Comments

@jiesia
Copy link
Contributor

jiesia commented Oct 31, 2023

worker 的 runtime 需要和 entry 的不同,现阶段在 worker 中使用 import() 动态加载模块时,产物无法运行,原因是 worker 中无法使用 document 等全局变量:

  • entry 通过 script tag 来 load script
  • worker 则需要通过 importScripts
@jiesia
Copy link
Contributor Author

jiesia commented Nov 1, 2023

  1. hmr 的问题删掉了,看了下 webpack 也没有支持。
  2. worker 单独的 runtime 看起来必要性不大,只是 loadScript 的问题的话在 entry runtime 中添加判断 typeof document === 'undefined' 即可

@stormslowly
Copy link
Member

worker hmr 个人觉得不需要做热更,后继的话如果 worker 相关的代码变动回退到 reload 就足够了。

@stormslowly
Copy link
Member

看下 importScripts,是个同步的方法,估计 loadScript 里面把他“伪装"成异步的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants