要在IE11中运行Angular 8应用程序,你需要将应用程序设置为使用ES6 / ES2015。
首先,你需要确保已安装了以下软件包:
core-js
软件包:npm install core-js@3 --save
@babel/preset-env
软件包:npm install @babel/preset-env --save-dev
安装完这些软件包后,你可以按照以下步骤进行设置:
.babelrc
文件,并添加以下内容:{
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "usage",
"corejs": 3
}
]
]
}
这将告诉Babel使用ES6 / ES2015语法,并根据需要自动注入所需的polyfills。
tsconfig.json
文件中,将target
选项设置为es5
:{
"compilerOptions": {
"target": "es5",
...
}
}
polyfills.ts
文件中添加了必要的polyfills。你可以在src/polyfills.ts
文件中找到并打开它。import 'core-js/es6/array';
import 'core-js/es6/date';
import 'core-js/es6/function';
import 'core-js/es6/map';
import 'core-js/es6/number';
import 'core-js/es6/object';
import 'core-js/es6/parse-int';
import 'core-js/es6/parse-float';
import 'core-js/es6/regexp';
import 'core-js/es6/set';
import 'core-js/es6/string';
import 'core-js/es6/symbol';
import 'core-js/es6/weak-map';
import 'core-js/es6/weak-set';
import 'classlist.js'; // 如果你使用了Angular Material,则还需要添加这一行
import 'web-animations-js'; // 如果你使用了Angular动画,则还需要添加这一行
// ... 其他polyfills
// 如果你使用了Angular Flex Layout,请在此处导入 'flex-layout/esm5/style-polyfill.js'
// 一些浏览器可能不支持Intl API,因此你可能需要添加以下polyfill
import 'intl';
import 'intl/locale-data/jsonp/en';
确保你已添加了所有需要的polyfills。根据你的应用程序所使用的功能,这个列表可能会有所不同。
完成上述步骤后,重新构建和运行你的Angular 8应用程序。现在,它应该可以在IE11中正常运行了。