create-react-app 保留 post-ES5 JavaScript

create-react-app keeps post-ES5 JavaScript

我正在使用 create-react-app 的 TypeScript 风格:

npx create-react-app my-app --typescript

当我构建应用程序时,包中仍然包含 post-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';