Angular 8 Web Workers 在 IE 中被破坏 [英] Angular 8 web workers are broken in IE

查看:25
本文介绍了Angular 8 Web Workers 在 IE 中被破坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从 Angular 7 迁移到 8,发现我们为运行后台任务而设置的 web-worker 在 IE 11 中运行时不再执行(大概更早).Edge、Chrome,其他都很好,只有 IE 11.

Migrating from Angular 7 to 8 and discovered that the web-worker we had setup to run a background task is no longer executing when run in IE 11 (and presumably earlier). Edge, Chrome, all the others were fine just IE 11.

Devtools 抱怨语法错误并引用了 es-2015.js 文件.

Devtools is complaining about syntax errors and referencing an es-2015.js file.

推荐答案

Angular 8 摒弃了传统的 polyfill 技术,以便与 ES6+ 和 ES5 兼容,使用差异构建来分离 ES5 和 ES6+ 脚本.这在主要应用组件中运行良好,但网络工作者在自己的线程中运行自己的进程,并且不再可以访问 polyfiller.

Angular 8 did away with the traditional polyfill techniques for compatibility with ES6+ and ES5 using differential builds to separate ES5 and ES6+ scripts. This works fine in the main app components, but web workers run their own processes in their own threads and no longer have access to the polyfillers.

最终的解决方案比我想象的要简单得多.确保 Web Worker 中的代码符合 ES5,并且可以在 IE 中运行.

Ultimately the solution was a lot simpler than I thought it would be. Make sure the code inside web worker is ES5 compliant and it will run in IE.

对于我们的网络工作者来说,这意味着删除任何箭头函数 (=>) 并将它们替换为传统的函数声明和带有老式串联的字符串插值.

For our web worker that meant removing any arrow functions (=>) and replacing them with a traditional function declaration and string interpolation with old fashioned concatenation.

// instead of 
myClass.doSomething( myVar => { console.log(`Look what I have in ${myVar}` } );

// do it old school
myClass.doSomething( function (myVar) { console.log('Look what I have in ' + myVar } );

(还有一些其他帖子建议手动放入 polyfill(此处) 但我无法在 web-worker 中成功导入和加载 polyfill.)

(There were some other posts suggesting manually putting in the polyfill (here) but I couldn't quite get the polyfills to import and load successfully inside the web-worker.)

这篇关于Angular 8 Web Workers 在 IE 中被破坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆