如何使用Create React App 3.0支持IE 11? [英] How do I support IE 11 with Create React App 3.0?

查看:126
本文介绍了如何使用Create React App 3.0支持IE 11?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着Create React App 3.0的发布和浏览器列表的添加,增加对IE 11的支持是微不足道的,但是如果您不知道在哪里看,很难找到这些步骤。该文档列出了受支持的浏览器,并显示了默认的浏览器列表配置( https ://facebook.github.io/create-react-app/docs/supported-browsers-features ),但这不是您需要知道的全部内容。

With the release of Create React App 3.0 and the addition of browserlist, adding support for IE 11 is trivial, but the steps can be hard to find if you don't know where to look. The documentation lists "Supported Browsers" and shows the default browserslist configuration ( https://facebook.github.io/create-react-app/docs/supported-browsers-features ) but that isn't all you need to know.

使用生产设置检查browserl.ist时,您会看到IE 11的使用率仍比Edge更高( https://browserl.ist/?q=%3E0.2%25%2C+not+dead%2C+not+op_mini+all )使用默认的CRA 3应用程序,您将在main.chunk.js中遇到语法错误,并在应用程序中使用IE 11出现其他错误。

Checking browserl.ist with the production settings you'll see IE 11 has greater usage than Edge still ( https://browserl.ist/?q=%3E0.2%25%2C+not+dead%2C+not+op_mini+all ) With a default CRA 3 app you'll get Syntax Error in main.chunk.js and other errors in your app with IE 11.

推荐答案

要停止错误并获得在IE 11中运行的默认create-react-app React应用程序:

To stop the errors and get a default create-react-app React application working in IE 11:


  1. 创建您的具有 npx create-react-app [AppName]
  2. 的基本应用程序
  3. 添加 import'react-app-poly fill / ie11'; 到index.js的最上方

  4. 如果您需要IE 11不支持的通用标准函数,例如Array.find()添加 import'react-app-polyfill / stable'; 在index.js的第一行下方

  5. 在package.json复制中生产浏览器列表进行开发,以便您可以在IE11和将在生产环境中运行的所有其他浏览器中进行测试

  6. 删除node_modules / .cache目录

  1. Create your basic application with npx create-react-app [AppName]
  2. Add import 'react-app-polyfill/ie11'; to the VERY top of index.js
  3. If you need common standard functions like Array.find() that are not supported in IE 11 add import 'react-app-polyfill/stable'; just below the first line in index.js
  4. In package.json copy the production browserlist to development so you can test in IE11 and all other browsers that will work in production
  5. Delete the node_modules/.cache directory

这篇关于如何使用Create React App 3.0支持IE 11?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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