我使用的是TypeScript风格的create-react-app:
npx create-react-app my-app --typescript
[当我构建应用程序时,捆绑软件仍然包含ES5后代码,例如Symbol。我想念什么?我的tsconfig文件:
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": [
"src"
]
}
[我发现create-react-app有一个关联的polyfill程序包,称为React-app-polyfill not included in the solution by default。
仅将目标设置为ES5还不够,您还需要get the polyfill package并在代码中引用它。例如对于IE11支持:
// This must be the first line in src/index.js
import 'react-app-polyfill/ie11';