create-react-app保留ES5后的JavaScript [英] create-react-app keeps post-ES5 JavaScript

查看:78
本文介绍了create-react-app保留ES5后的JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using the TypeScript flavor of create-react-app:

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

在构建应用程序时,捆绑软件仍然包含ES5后代码,例如Symbol.我想念什么?我的tsconfig文件:

When I build the app, the bundle still includes post-ES5 code such as Symbol. What am I missing? My tsconfig file:

{
  "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,

I found out that create-react-app has an associated polyfill package called react-app-polyfill, not included in the solution by default.

仅将目标设置为ES5还不够,您还需要

Setting the target to ES5 is not enough, you also need to get the polyfill package and reference it in the code. For example for IE11 support:

// This must be the first line in src/index.js
import 'react-app-polyfill/ie11';

这篇关于create-react-app保留ES5后的JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆