angular - 当目标为 es6 时,Angular 应用程序未在 IE 11 中加载
问题描述
我正在创建一个新应用程序,我的目标浏览器是 IE11。当我将目标用作 es6 时,我的应用程序无法加载并显示错误,如下所示。
但是当我将目标更改为 es5 时,一切似乎都正常。我的疑问是,添加 polyfill 是为了确保旧版浏览器支持较新的 JavaScript 函数。我已经启用了所有针对 es6 的 polyfill,如下所示
/**
* This file includes polyfills needed by Angular and is loaded before the app.
* You can add your own extra polyfills to this file.
*
* This file is divided into 2 sections:
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
* file.
*
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
*
* Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
*/
/***************************************************************************************************
* BROWSER POLYFILLS
*/
/** IE9, IE10 and IE11 requires all of the following polyfills. **/
import 'core-js/es6/symbol';
import 'core-js/es6/object';
import 'core-js/es6/function';
import 'core-js/es6/parse-int';
import 'core-js/es6/parse-float';
import 'core-js/es6/number';
import 'core-js/es6/math';
import 'core-js/es6/string';
import 'core-js/es6/date';
import 'core-js/es6/array';
import 'core-js/es6/regexp';
import 'core-js/es6/map';
import 'core-js/es6/weak-map';
import 'core-js/es6/set';
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
import 'classlist.js'; // Run `npm install --save classlist.js`.
/** IE10 and IE11 requires the following for the Reflect API. */
import 'core-js/es6/reflect';
/** Evergreen browsers require these. **/
// Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove.
import 'core-js/es7/reflect';
/**
* Web Animations `@angular/platform-browser/animations`
* Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
* Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
**/
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
/**
* By default, zone.js will patch all possible macroTask and DomEvents
* user can disable parts of macroTask/DomEvents patch by setting following flags
*/
// (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
// (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
// (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
/*
* in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
* with the following flag, it will bypass `zone.js` patch for IE/Edge
*/
// (window as any).__Zone_enable_cross_context_check = true;
/***************************************************************************************************
* Zone JS is required by default for Angular itself.
*/
import 'zone.js/dist/zone'; // Included with Angular CLI.
/***************************************************************************************************
* APPLICATION IMPORTS
*/
我的问题是,即使所有针对 es6 的 polyfill 都已导入,为什么我的应用程序不来?我在这里错过了什么吗?请帮忙。
对提议的副本的回应
我相信这不是这个问题的重复。我有解决方案(将 ES6 更改为 ES5)。但是该问题的答案并没有说明为什么即使添加了 polyfill 也不支持 ES6。我相信这个问题与预期的答案完全不同。
解决方案
正如 Angular 文档所述:Differential loading is currently only supported when using es2015 as a compilation target. When used with targets higher than es2015, a warning is emitted during build time.
https ://v8.angular.io/guide/deployment#differential-loading
这仅仅意味着在 tsconfig 中你必须使用"target": "es2015",
您还必须确保正确配置 browserslist(或 package.json)文件。可能你想添加一个 zone-flags.ts。
最后,如果你使用 Object.values 之类的东西,你也必须import 'core-js/es7/object';
进入你的 polyfills 文件,当然如果你使用其他东西的话。
推荐阅读
- javascript - Vue.js 在 v-for 中重写 orderBy 过滤器
- javascript - 每个网页都有 DOM 和 body 元素吗?
- javascript - 如何在没有堆栈跟踪的情况下调试缩小的 JS 前端错误?
- swift - 获取范围内 UIView 的平均颜色
- machine-learning - Dialogflow 建议下一个最佳意图作为响应
- podio - 有没有办法区分钩子?
- c# - 如何发出 http web asyncGET 请求
- wordpress - Wordpress / Woocommerce Hook into a Function
- c++ - 字符串操作主题消息
- docker - 如何在 ConnectionString 中引用 Docker 容器