create-react-app保留ES5之后的JavaScript

问题描述 投票:0回答:1

我使用的是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"
  ]
}
typescript create-react-app ecmascript-5
1个回答
0
投票

[我发现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';
© www.soinside.com 2019 - 2024. All rights reserved.