IE中的ES6编译问题

时间:2017-03-23 12:21:23

标签: visual-studio angular typescript

我目前正在处理使用Angular2 / ES6在Chrome上运行的其中一个应用程序。

但是,客户希望在IE上运行相同的应用程序。我知道IE不支持ES6.Iust想知道,如果有相同的方法可以实现。

P.S - 我正在使用Visual Studio 2015进行构建,下面是我的tsconfig.json。

{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
}
}

我有什么方法可以使用2个目标,比如其他工作作为后备?

1 个答案:

答案 0 :(得分:0)

您可以通过使用Babel将ES6脚本编译为ES5来保持ES6 JavaScript完整,并且可以将Angular 2与Babel结合使用,而不会牺牲TypeScript的使用,如this article所示:< / p>

  

使用方法

npm install -D babel-preset-es2015 babel-preset-angular2
     

将预设添加到.babelrc。请注意,预设的顺序很重要。

{
    "presets": ["es2015", "angular2"]
}
     

有关更完整的示例,请参见babel-angular2-app