我正在尝试使我的代码在IE11上运行,但是,箭头功能存在问题。我无法弄清楚如何从构建中删除它们,并用function() {}
替换它们。
似乎它们已从我的main.js
中删除,但是在vendor.js
文件中,箭头功能仍然存在。如何删除它们?
我有一个看起来像这样的浏览器列表:
> 0.5%
last 2 versions
Firefox ESR
not dead
IE 9-11
我也有一个看起来像这样的tsconfig.json
:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"downlevelIteration": true,
"importHelpers": true,
"outDir": "../path/to/folder",
"sourceMap": true,
"declaration": false,
"module": "esnext",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}
您可以在"files"
中使用"include"
,"exclude"
和tsconfig.json
属性来指定要编译的文件。我敢肯定,默认情况下它不会触摸.js
文件。https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#exampleshttps://www.typescriptlang.org/docs/handbook/tsconfig-json.html#details
如果使用的是Angular 8,则可以参考以下步骤在IE 11中支持Angular 8:
在tsconfig-es5.app.json
旁边创建具有以下内容的新tsconfig tsconfig.app.json
:
{
"extends": "./tsconfig.app.json",
"compilerOptions": {
"target": "es5"
}
}
在angular.json
中,在build
和serve
目标下添加两个新的配置部分以提供新的tsconfig:
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
...
},
"configurations": {
"production": {
...
},
"es5": {
"tsConfig": "./tsconfig-es5.app.json"
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
...
},
"configurations": {
"production": {
...
},
"es5": {
"browserTarget": "yourAppName:build:es5"
}
}
},
使用以下命令使用此配置运行服务:
ng serve --configuration es5
以上步骤可以在投放过程中生成ES5版本。如果仍然无法解决问题,您可以提供一个最少的样本来重现该问题,以便我们可以进行测试。