微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript-IE11在Angular2(TS)中发布Angular CLI项目,polyfills无法正常工作

我正在使用具有polyfills.ts的ugul-cli 1.0.0-beta.16,如下所示:

// This file includes polyfills needed by Angular 2 and is loaded before
// the app. You can add your own extra polyfills to this file.
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/set';
import 'core-js/es6/reflect';

import 'core-js/es7/reflect';
import 'zone.js/dist/zone';

但是此pollyfills文件在IE11上不起作用,并且在Chrome,Firefox,EDGE和我的main.ts上都可以运行,如下所示:

import "./polyfills.ts";
import {platformbrowserDynamic} from "@angular/platform-browser-dynamic";
import {enableProdMode} from "@angular/core";
import {environment} from "./environments/environment";
import {AppModule} from "./app/";

if (environment.production) {
  enableProdMode();
}

platformbrowserDynamic().bootstrapModule(AppModule);

在IE11上运行此命令会在胖箭头表达错误显示错误

SCRIPT1002: Syntax error

对于位于此位置的minifiedjs:

function arrayUnion(arr1, arr2) {
    return arr1
        .concat(arr2.filter(v => arr1.indexOf(v) === -1));
}

这就是我的tsconfig.json的样子

    {
  "compilerOptions": {
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": ["es6", "dom"],
    "mapRoot": "./",
    "module": "es6",
    "moduleResolution": "node",
    "outDir": "../dist/out-tsc",
    "sourceMap": true,
    "target": "es5",
    "typeRoots": [
      "../node_modules/@types"
    ]
  }
}

@Cleton这就是我的tsconfig的样子

解决方法:

您可能瞄准es6,它将箭头功能编译为箭头功能

let fn = () => console.log("hey");

编译为:

let fn = () => console.log("hey");

但是,如果您以es5为目标,它将编译为:

var fn = function () { return console.log("hey"); };

似乎IE11(或任何其他版本的资源管理器)为do not yet support arrow functions.
如果要支持它,则必须以es5或更低版本为目标,因为箭头功能没有pollyfil.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐