IE 中的 ES6 编译问题 [英] ES6 Compilation Issue in IE
问题描述
我目前正在开发一款使用 Angular2/ES6 在 Chrome 上运行的应用程序.
I am Currently Working on One of the Applications which works on Chrome using Angular2/ES6.
但是,客户希望在 IE 上运行相同的应用程序.我知道 IE 不支持 ES6.只是想知道,是否有可以实现相同的方法.
However,Client wants the same Application to run on IE.I am aware of IE NOT Supporting ES6.Just wanted to know ,if there is a way the same Can be Achieved.
P.S - 我正在从 Visual Studio 2015 进行构建,下面是我的 tsconfig.json.
P.S - I am doing Build from my Visual Studio 2015,and below is my tsconfig.json.
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
}
}
有什么办法可以使用 2 个目标,以便其他作品作为后备?
Is there any way I can use 2 targets,such that Other Works as fallback?
推荐答案
你可以使用 Babel 将 ES6 脚本编译为 ES5,并且可以在不牺牲使用 TypeScript 的情况下使用 Babel 和 Angular 2,如 这篇文章:
You could keep your ES6 JavaScript intact by using Babel to compile ES6 scripts to ES5, and it's possible to use Babel with Angular 2 without sacrificing the use of TypeScript, as shown in this article:
使用方法
npm install -D babel-preset-es2015 babel-preset-angular2
将预设添加到 .babelrc.请注意,预设的顺序很重要.
Add presets to .babelrc. Note that the presets' order is important.
{
"presets": ["es2015", "angular2"]
}
有关更完整的示例,请参阅 babel-angular2-app.
See babel-angular2-app for more complete example.
这篇关于IE 中的 ES6 编译问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!