Angular ng serve 不包含 polyfill——IE11/Edge 仅在运行 ng build --prod 时工作

标签 angular angular-cli polyfills

为此,我尝试同时使用 npm run start 和 ng serve。在所有情况下,生成的应用程序在 IE11 和 Edge 中根本无法运行。

围绕 IE11 和 Edge 存在许多其他问题,但这严格来说是关于 Angular CLI 在运行 ng serve 时无法有效包含 polyfill 的问题。

    ng serve

** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **

Date: 2018-10-01T15:27:24.006Z
Hash: f7ee38fccff1d585e3ed
Time: 12681ms
chunk {main} main.js, main.js.map (main) 119 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 452 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 5.22 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 86.4 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 7.2 MB [initial] [rendered]
i 「wdm」: Compiled successfully.

这是绝对必要的,因为我需要使我的应用程序完全兼容 IE11/Edge,而且我无法构建生产环境来检查是否使 div 居中。

编辑1:

运行 ng serve --prod 似乎确实有效,但天哪,修改某些东西时速度很慢。仍然想找到解决这个问题的方法。

最佳答案

这对你来说可能有点晚了,但万一其他人发现它......我有一个类似的问题,我的 Angular 7 应用程序从头开始使用 CLI 工作,除了微软的 EDGE 浏览器,当从 ng serve 运行时. (是的,IE 11 工作,但 EDGE 没有。去看看。)

无论如何,我找到了这篇文章: https://github.com/angular/angular-cli/issues/8596

用户 clydin 的评论为我提供了修复(即使他们在谈论 Safari)。他们说:

The error is due to the development server's live reload client code (from webpack-dev-server) which requires basic ES2015 support. This will not affect builds (production or otherwise) of the application as the live reload code is not present. Live reload functionality can be disabled, if desired, via the --no-live-reload option. Due to a defect in safari 10, enabling source maps on ng serve (the default) results in a similar error. This does not affect Safari 11.

我在我的 package.json 中创建了一个脚本,当我运行这个脚本时,EDGE 工作了。您也可能会幸运地使用此标志。

"app-edge": "ng serve --host 0.0.0.0 --disable-host-check --no-live-reload"

关于Angular ng serve 不包含 polyfill——IE11/Edge 仅在运行 ng build --prod 时工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52594445/

相关文章:

声明了 Angular 5 'inputClick' 但它的值从未被读取

angular - Firebase Firestore - 限制用户可以创建的产品文档数量

angular - ng 命令给出错误,SyntaxError : Unexpected token ). centos 7

html - *ngFor 下一个元素

javascript - 如何在 webpack 中正确填充 URLSearchParams?

reactjs - create-react-app 的 ES6 Polyfill 不起作用

node.js - Webpack模块沿着输出文件分布

angular - 如何在项目中使用 Angular 库中的服务

javascript - Angular2 自定义事件

angular - 我无法在 asp.net core spa 中添加带有 Angular cli 的新组件