【问题标题】:How to link es6 polyfill in a angular 2 application如何在 Angular 2 应用程序中链接 es6 polyfill
【发布时间】:2017-06-27 05:04:42
【问题描述】:

我开发了一个 Angular 2 应用程序,它在 Android 4.1.x 和更多的浏览器中无法运行。

我的应用中包含的唯一指向 Polyfills 的链接如下:

<script src="node_modules/core-js/client/shim.min.js"></script>

我阅读了 Angular2 文档 (here),发现我必须引入 ES6 Polyfill 才能使其在 Android 设备上运行,但我不知道如何链接它。包含在core-js 模块中,但是如何将其插入到应用程序中?

【问题讨论】:

  • 您是否能够确定要包含 @B 的 ployfill 文件。西尔沃?
  • 不,但我用另一种方式解决了...我用 npm install 安装了 @types/core-js": "^0.9.35" 并在 tsconfig.json 中将我的目标从 es6 更改为 es5。然后将以下指令插入到“compilerOptions”中:“typeRoots”:[“../node_modules/@types”],“types”:[“core-js”],它起作用了。
  • 感谢您的解决方案。此外,您决定使用 core-js 与其他 npm 模块(如 angular2-ie-shims link)是否有原因?我想知道 polyfill 是否有任何不同
  • 嗯,不,只是...我试过了,它成功了 :) 你也设法让它工作了吗?
  • IE-shims 用于 Internet Explorer。 core-js 也适用于 android4.1+ 。但 PBandJen 的回答对我不起作用。目标已经是 es5 和 typeRoots": [ "../node_modules/@types] 我只添加了 "types" : [ "core-js" ] 但没有成功。这个 angular2 站点 ng-bootstrap.github.io/#/home 工作正常,但它有哈希策略

标签: android angular ecmascript-6 cross-browser polyfills


【解决方案1】:

例如在您的捆绑包中 导入'core-js/es6';

【讨论】:

    【解决方案2】:

    您必须将其插入到您的&lt;head&gt; 中,您可以通过在计算机上查看页面源来检查它是否已加载。

    【讨论】:

      猜你喜欢
      • 2014-01-05
      • 2017-11-07
      • 1970-01-01
      • 2016-03-10
      • 2016-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多